Solved

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

Posted on 2008-10-16
1
1,046 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
[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
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

What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

Question has a verified solution.

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

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…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

622 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