Blank column of the datagridview datagri. by default, the background color of the selected row is selected. In the datagridview, add the check box to change the check box status.

Source: Internet
Author: User

Example:

1. the blank column of the datagridview refers to that each row of the datagridview dview has a row header and cannot be bound to or operated on. I don't know if you have ever had a headache. I used to ignore it. Later, I found that the datagridview attribute panel has a rowheadersvisible attribute that sets whether the row header is displayed, set the value to false.

2. By default, the background color of the selected row of the datagridview is blue, which looks ugly. After the datagridview data is bound, the background color of the first row is blue by default, however, the first row is not selected. To solve this problem, a datagridviewcheckboxcolumn is added to the row. Whether the row is selected depends on whether the datagridviewcheckboxcolumn is selected, now, let's talk about the background color of the selected row. click the button on the Right of rowdefaultcellstyle in the datagridview attribute to open the cellstyle generator and change selectionbackcolor to the background color you want. do not set selectionbackcolor and selectionforecolor to the same value.

3. You can add a check box to the dview by specifying the columntype value of a column as the datagridviewcheckboxcolumn. As long as you have added a column, it is no stranger, but to change its check status, it took me half a day and now the problem has been solved. Let's look back, how can we use a simple word to describe it,

Private void maid (Object sender, maid E)
{// When any cell content in a row is clicked
If (maid [E. columnindex]. Name = "column0 ")
{
Datagridviewcheckboxcell dgcb = (datagridviewcheckboxcell) datagridview1.rows [E. rowindex]. cells ["column0"];
If (bool) dgcb. formattedvalue)
{
Dgcb. value = false;
}
Else
{
Dgcb. value = true;
}
}
}

OK. I just transferred to winform for development. I used to work on a website. I used vs2008. If not, please correct it.

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.