Bind the DataGrid in winform

Source: Internet
Author: User

Copy codeThe Code is as follows: this. dgTankView. Columns ["ID"]. DataPropertyName = "ID ";
This. dgTankView. Columns ["TankName"]. DataPropertyName = "Name ";
This. dgTankView. Columns ["Area"]. DataPropertyName = "Area ";
This. dgTankView. Columns ["Type"]. DataPropertyName = "Type ";
This. dgTankView. Columns ["Status"]. DataPropertyName = "Status ";
This. dgTankView. Columns ["Material"]. DataPropertyName = "Material ";
This. dgTankView. Columns ["MaterialCategory"]. DataPropertyName = "MaterialCategory ";
This. dgTankView. Columns ["MaxLevel"]. DataPropertyName = "MaxLevel ";
This. dgTankView. Columns ["MinLevel"]. DataPropertyName = "MinLevel ";
This. dgTankView. Columns ["MaxCapacity"]. DataPropertyName = "MaxCapacity ";
This. dgTankView. Columns ["MinCapacity"]. DataPropertyName = "MinCapacity ";
This. dgTankView. Columns ["Code"]. DataPropertyName = "Code ";

//// Set columns width
// This. dgTankView. Columns ["MaterialCategory"]. Width = 80;
// This. dgTankView. Columns ["Material"]. Width = 240;
// This. dgTankView. Columns ["TankName"]. Width = 100;
// This. dgTankView. Columns ["Area"]. Width = 80;
// This. dgTankView. Columns ["MaxLevel"]. Width = 100;
// This. dgTankView. Columns ["MinLevel"]. Width = 100;
// This. dgTankView. Columns ["MaxCapacity"]. Width = 100;
// This. dgTankView. Columns ["MinCapacity"]. Width = 100;
// This. dgTankView. Columns ["Type"]. Width = 60;

// This. dgTankView. Columns ["Status"]. AutoSizeMode = maid. Fill;

This. dgTankView. AutoGenerateColumns = false;
This. dgTankView. DataSource = tankviews;
Int rowCount = dgTankView. RowCount;
If (SelectedIndex <rowCount | SelectedIndex> = rowCount)
{
This. dgTankView. Rows [0]. Selected = true;
}
Else
{
This. dgTankView. Rows [this. SelectedIndex]. Selected = true;
}

For (int I = 0; I <dgrdSelectedMaterial. RowCount; I ++)
{
If (decimal. parse (dgrdSelectedMaterial. rows [I]. cells ["ColumnSelectedMinRatio"]. value. toString ()> decimal. parse (dgrdSelectedMaterial. rows [I]. cells ["ColumnSelectedMaxRatio"]. value. toString ()))
{
MessageUtil. info (string. format (Config. messageManager [MessageGroupHelper. formatToName (int) MessageGroup. client), "1959"]. toString (), dgrdSelectedMaterial. rows [I]. cells ["ColumnSelectedName"]. value. toString ()));
Return false;
}
}

RowHeardersVisible = false
Selection Mode = Full row Select
ColumnHeaderDefault = alignCenter

/// High
DgrdStaticTank. ColumnHeadersHeight = 40;
DgrdBlendMaterialQuality. ColumnHeadersHeightSizeMode = maid. AutoSize;

Width:
DgrdBlendMaterial. AutoGenerateColumns = false;
DgrdBlendMaterial. AutoSizeColumnsMode = maid. Fill;
DgrdBlendMaterial. Columns ["ColumnMaterialTankName"]. Width = 80;

----------------------------------------------------------

This. Maid. Value; // The Value of the currently active cell

This. dataGridView1.CurrentCell. RowIndex; // row of the currently active cell

This. Maid. ColumnIndex; // column of the currently active cell

This. Maid [5]. Cells [3]. Value; // The Value of the cell in column 6th of row 4th
DataGridView [col, row]. Value = obj;

ControlUtil. SetDataGridViewStyleForMasterData (dgrdBlendMaterial );
DgrdBlendMaterial. AutoGenerateColumns = false;
DgrdBlendMaterial. AutoSizeColumnsMode = maid. Fill;
DgrdBlendMaterial. Columns [& quot; ColumnMaterialName & quot;]. Width = 200;

UcPagingTank. DataBindings. Add ("PageIndex", tankListModel, "PageIndex", true, performanceupdatemode. Never );

----- Display format of a column ----
DgrdTank. Columns ["ColumnTimeStamp"]. DefaultCellStyle. Format = Config. AppConfig. DateTimeFormat;

--- Obtain the value of the selected column -----
StrCurRoleID = dgrdRoleList. SelectedRows [0]. Cells [0]. FormattedValue. ToString ();

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.