WinForm DataGridView controls, duck layouts

Source: Internet
Author: User

1.DataGridView controls

Show data table


(1) Background data binding:
list<xxx> list = new list<xxx> ();
Datagridview1.datasource = list;

Setting does not automatically generate columns, this property is not in the properties panel
Datagridview1.autogeneratecolumns = false;

Cancel load Default Check first row
datagridview1.clearselection ();

(2) Front desk:
Small triangle arrow, cancel editable, add, delete function;
Columns The collection property, add the column
Set the displayed text in HeaderText
DataPropertyName Setting the field name or database column name of the binding
SelectionMode--Set selection method, Fullrowselect can only select BOC
MultiSelect-whether multiple lines of content can be selected

(3) Value:
Remove the value of the selected cell:
All selected cells are in the Datagridview1.selectedcells
if (DataGridView1.SelectedCells.Count > 0)
{
MessageBox.Show (datagridview1.selectedcells[0]. Value.tostring ());
}

Remove the selected line contents:

if (DataGridView1.SelectedRows.Count > 0)
{
MessageBox.Show (datagridview1.selectedrows[0]. Cells[0]. ToString ());
}

gets the object used to populate the row bindings:
//Row Object Usage properties: Databounditem
Student SSS = datagridview1.selectedrows[0]. Databounditem as student;

2.Dock Properties

Top: Up, height constant, left and right (width) stretch
Bottom: Bottom, height constant, left and right stretch
Fill: Fills the entire area
Left: Right, width unchanged, stretched up and down
Right: Left, width unchanged, stretched up and down

WinForm DataGridView controls, duck layouts

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.