0
如何在DataGrid中編輯特定的細胞,並接受與在DataGrid textbox.the其他細胞的細胞數據不需要在C#.NET 2005 感謝小號編輯 提前編輯DataGrid行
如何在DataGrid中編輯特定的細胞,並接受與在DataGrid textbox.the其他細胞的細胞數據不需要在C#.NET 2005 感謝小號編輯 提前編輯DataGrid行
試試吧,
DataTable dt = new DataTable();
dt.Columns.Add("No",typeof(int));
dt.Columns.Add("Name");
dt.Rows.Add(1, "A");
dt.Rows.Add(2, "B");
dt.Columns[0].ReadOnly = true;
dataGridView1.EditMode = DataGridViewEditMode.EditOnKeystroke;
dataGridView1.DataSource =dt;
如果你試圖直接在數據網格更新:
// Override the OnMouseClick event.
protected override void OnMouseClick(DataGridViewCellMouseEventArgs e)
{
if (base.DataGridView != null)
{
// Get the location (Row/Column) of the selected cell.
Point point1 = base.DataGridView.CurrentCellAddress;
// e.ColumnIndex/e.RowIndex can be replaced with a hard-coded
// value if you only want a specific cell, row, or column to
// be editable.
if (point1.X == e.ColumnIndex &&
point1.Y == e.RowIndex &&
e.Button == MouseButtons.Left &&
base.DataGridView.EditMode !=
DataGridViewEditMode.EditProgrammatically)
{
// Open the cell to be edited.
base.DataGridView.BeginEdit(true);
}
}
}
這將允許用戶編輯C直接。如果您代替e.ColumnIndex硬編碼值(例如:硬編碼爲5),則只有第5列是可編輯的。 e.RowIndex也一樣。