DataGridView in the Enditcommit () call, the contents of the cell is selected all, each input must be mouse click to locate the last to continue to enter

Source: Internet
Author: User

Because of some requirements, DataGridView is going to call Ecommitedit (Datagridviewdataerrorcontexts.commit) to commit the content as soon as it is entered, but after doing so, the control will be finished with what you have entered. , so the content is all selected (the internal principle I haven't time to understand, so not very clear, want to know people can tell me)

Solution:

To allow the user to enter a string of characters normally, after each call to the Commitedit () method, get the control's current cell corresponding to the control type TextBox Currenttextbox, call Currenttextbox's Select () method to position the cursor at the last character of the text, as shown in the following code

Base . Dgvdetail.commitedit (datagridviewdataerrorcontexts.commit);                 Base  as TextBox;                 if (currenttextbox!=nullnull)                     0); // prevent Commiteidt text from being selected all

Note also consider the case when calling the Commitedit () method when the bound control is not a TextBox

DataGridView in the Enditcommit () call, the contents of the cell is selected all, each input must be mouse click to locate the last to continue to enter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.