Link to home
Start Free TrialLog in
Avatar of Jess31
Jess31

asked on

DataGridView / BeginEdit(True) ?

Using vb.net/winform and DataGridView. On the CellEnter event I have BeginEdit(True). This is fine. Only that the cursor is placed at the end of whatever text exists. I would like to have the cursor either at the beginning of the text or for the entire text to be selected and whatever is typed erases it. How can I do this?
Avatar of Zhaolai
Zhaolai
Flag of United States of America image

By doing BeginEdit(True), the entire text is selected when clicking on the cell and typing anything into the cell does erase the selected text, which is what you want.

Do you not see the entire text being selected when clicking the cell? If so, you may have other event(s) which removes the selection.
ASKER CERTIFIED SOLUTION
Avatar of cheb1
cheb1

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

Private WithEvents thiscontrol as control
Private Sub Me.DataGridView_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles Me.DataGridView.EditingControlShowing
        Try
            If DataGridView.CurrentCell.ColumnIndex = "YourColumnIndex Then
                thiscontrol = CType(e.Control, TextBox)
                thiscontrol.SelectionStart=0
            Else
                thiscontrol = Nothing
            End If

Open in new window