Solved

DataGridView /  BeginEdit(True)  ?

Posted on 2010-08-23
3
1,692 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 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 Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

707 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