Solved

DataGridView /  BeginEdit(True)  ?

Posted on 2010-08-23
3
1,636 Views
Last Modified: 2013-11-08
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?
0
Comment
Question by:Jess31
3 Comments
 
LVL 17

Expert Comment

by:Zhaolai
ID: 33507535
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.
0
 
LVL 1

Accepted Solution

by:
cheb1 earned 500 total points
ID: 33507559
How about this:

 Dim editControl As DataGridViewTextBoxEditingControl = DirectCast(_your_grid.EditingControl, DataGridViewTextBoxEditingControl)

        If Not editControl Is Nothing Then
            editControl.SelectionStart = 0
            editControl.SelectionLength = editControl.Text.Length
        End If
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33508322

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

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question