Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

EditingControlShowing - How to pre-select text when user moves to new cell

Posted on 2008-10-16
1
Medium Priority
?
1,079 Views
Last Modified: 2013-12-17
Here's what I want to do:

In a Datagridview, if the user is editing a cell and has the cursor in, say, position 10, and then moves down or up to an adjacent cell, I want to the new cell to be in edit mode and have the cursor in position 10 with only that position selected (or none selected.) - similar to what you see in any text editor as you move up or down.

However, whenever I move to the next cell, it does go into edit mode, but the whole cell is selected even though I selected just that one position.
private void dgrSource_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            Control ctl = e.Control;
            DataGridViewTextBoxEditingControl dText = (DataGridViewTextBoxEditingControl)ctl;
                              
			if (lastPos > 0 && lastPos < dText.Text.Length)  //lastPos was previously captured and is correct
            {
                dText.SelectionStart = lastPos;
                dText.SelectionLength = 1;
            }
        }

Open in new window

0
Comment
Question by:stevelucy
1 Comment
 

Accepted Solution

by:
stevelucy earned 0 total points
ID: 22737304
I solved this by capturing the DataGridViewTextBoxEditingControl variable in the EditingControlShowing event, and performing the Select method in the CellEnter event.
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

916 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