C # winform datagridview usage Summary

Source: Internet
Author: User
1. the first blank column is not displayed.
The rowheadervisible attribute is set to false.

2. Click cell to select the entire row
Rowselectinmodel attribute settings
You can also use the cellclick event.

// Select the entire row
Private void maid cellclick (Object sender, maid E)
{
// E. rowindex>-1 otherwise, clicking the header is also called a column.
If (maid. Count> 0 & E. rowindex>-1)
{
// MessageBox. Show (E. rowindex. tostring ());
Datagridview1.rows [E. rowindex]. Selected = true;
}
}


3. Add button image button column events
To display text on the button, set the text attribute. There is no value by default. However, it is not clear why the datapropertyname field is not displayed. Therefore, the values of recognition records such as ID must be placed in other columns. // Button event
Private void maid (Object sender, maid E)
{
If (E. columnindex = 1)
{
MessageBox. Show (maid [E. rowindex]. cells [1]. value. tostring ());
}
}

4. Add an external button to obtain the selected private void button#click (Object sender, eventargs E)
{
If (maid. Count> 0)
{
MessageBox. Show (maid [0]. cells [1]. value. tostring ());
}
}

5. other settings.
Whether multiple rows can be selected: multiselect.
Fields in the data table are not automatically bound.
Extend the width of the last column to the upper-level width: Set autosizemodel to fill

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.