Data display operations:
Dgbill.columns[0]. DataPropertyName = "Key1";
DGBILL.COLUMNS[1]. DataPropertyName = "Key2";
DGBILL.COLUMNS[2]. DataPropertyName = "Key3";
DataTable dt = new DataTable ();
Dt. Columns.Add ("Key1", Type.GetType ("System.String"));
Dt. Columns.Add ("Key2", Type.GetType ("System.String"));
Dt. Columns.Add ("Key3", Type.GetType ("System.String"));
DataRow dr = null;
Dr = dt. NewRow ();
dr["Key1"] = "Key1";
dr["Key1"] = "Key2";
dr["Key1"] = "Key3";
Dt. Rows.Add (DR);
This.dgBill.DataSource = DT;
Select a row of data:
Right-click menu items
private void Dg1_cellmousedown (object sender, DataGridViewCellMouseEventArgs e)
{
if (E.button = = mousebuttons.right)
{
if (e.rowindex >= 0)
{
If the row is already selected, it is no longer set
DG1. ClearSelection ();
DG1. Rows[e.rowindex]. Selected = true;
Set up when moving forward
DG1. CurrentCell = DG1. Rows[e.rowindex]. Cells[0];
Popup Action Menu
Contextmenustrip1.show (mouseposition.x, MOUSEPOSITION.Y);
}
}
}
When you select a menu, you get the data for the right-click row
DataGridViewRow rowdata = Dgbill.currentrow;
if (rowdata! = null)
{
if (rowdata.cells["ID"). Value = null)
{
}
Else
{
MessageBox.Show ("Data Conversion exception", "hint", MessageBoxButtons.OK);
}
}
Simple operations for C # WinForm DatagridView