?
Solved

DataGridView /  BeginEdit(True)  ?

Posted on 2010-08-23
3
Medium Priority
?
1,729 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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 Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

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 …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

770 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