直接更改 DataGridView 中的值

Uni*_* Le 2 c# datagridview cell windows-forms-designer

如何更改DataGridViewWindows 窗体中所有单元格的值?我想直接在 Windows 窗体中更改,例如直接在单元格中键入

我有一张像:

AA    BB    CC
--------------
1     aa    ac
2     bb    fd// I type here and change the value to kk
Run Code Online (Sandbox Code Playgroud)

代码:

DataGridViewTextBoxColumn AA= new DataGridViewTextBoxColumn();
MsgIDHex.HeaderText = "AA";
MsgIDHex.DataPropertyName = "AA";
DataGridViewTextBoxColumn BB= new DataGridViewTextBoxColumn();
MsgIDHex.HeaderText = "BB";
MsgIDHex.DataPropertyName = "BB";
DataGridViewTextBoxColumn CC= new DataGridViewTextBoxColumn();
MsgIDHex.HeaderText = "CC";
MsgIDHex.DataPropertyName = "CC;
dataGridView1.DataSource = result;
dataGridView1.Columns.AddRange(AA, BB, CC};
Run Code Online (Sandbox Code Playgroud)

我应该做些什么DataGridViewTextBoxEditingControl吗?

Vyk*_*tor 5

您可以简单地执行此操作(假设您想以编程方式更改一个值):

dataGridView1.Rows[RowNumber].Cells[CC.Index].Value = newValue;
Run Code Online (Sandbox Code Playgroud)

以及如何启用某些单元格的编辑已经在这里解释。