mjb3030 Posted November 4, 2003 Posted November 4, 2003 I am using the following delegate for the ENTER event of all my textboxes on a particular form. Private Sub TextBoxSelection(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim tb As TextBox tb = sender tb.SelectionLength = tb.Text.Length tb.SelectionStart = 0 End Sub The problem is that if I type text into a textbox, exit the box, then re-enter it, the text is not selected. The cursor is set at the 0 position as it should be, but no text is selected. HOWEVER, if I then leave the textbox and re-enter it (without making any changes) the text IS all selected. Why doesn't it happen properly the first time? Quote
Moderators Robby Posted November 4, 2003 Moderators Posted November 4, 2003 Get rid of the tb declare and do this. tb.SelectionLength = directcast(sender,textbox).Text.Length also, place the SelectionStart before the length. Quote Visit...Bassic Software
mjb3030 Posted November 4, 2003 Author Posted November 4, 2003 The directcast statement gave me an error, but I put the selectionstart first and that fixed the problem. Thanks! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.