Solved

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

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

752 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