Solved

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

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now