Solved

DataGridView /  BeginEdit(True)  ?

Posted on 2010-08-23
3
1,584 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now