Datagridviewcheckboxcolumn's Problem

Source: Internet
Author: User

Environment: VS2013

System: Win7 32-bit

Problem: Using column style datagridviewcheckboxcolumn in DataGridView:

(1) with the mouse click on the interface, so that the Datagridviewcheckboxcolumn column of the Multiple checkbox state changes, when the mouse is still selected datagridviewcheckboxcolumn column of a cell, when the state is obtained, Found the selected cell value to get the result error;

Get method: Dr. cells["Checkitem"]. Value.tostring ()

            foreach (DataGridViewRow dr in Dgvsoftup.rows)            {                if (Dr. cells["Checkitem"]. Value = null)                {                    if (Convert.toboolean (Dr. cells["Checkitem"]. Value.tostring ()))                    {                         ...}                }}            

Workaround (from http://www.cnblogs.com/gossip/archive/2008/12/02/1346047.html):

Added in the Currentcelldirtystatechanged event of DataGridView: Dgvsoftup.commitedit (Datagridviewdataerrorcontexts.commit);

        private void Dgvsoftup_currentcelldirtystatechanged (object sender, EventArgs e)        {            Dgvsoftup.commitedit ( datagridviewdataerrorcontexts.commit);        }

(2) When setting the checkbox state through code, the status setting is not valid when the unit is in cells state.

The setup code is as follows:

           foreach (DataGridViewRow dr in Dgvsoftup.rows)            {                 Dr. cells["Checkitem"]. Value = true;            }

Workaround, after setting, add EndEdit ():

     Dgvsoftup.endedit ();

Datagridviewcheckboxcolumn's Problem

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.