C# 直接更改DataGridView中的值
如何更改Windows窗体中所有单元格的值?我想直接在Windows窗体中进行更改,就像直接在单元格中键入一样 我有一张像这样的桌子:C# 直接更改DataGridView中的值,c#,datagridview,cell,windows-forms-designer,C#,Datagridview,Cell,Windows Forms Designer,如何更改Windows窗体中所有单元格的值?我想直接在Windows窗体中进行更改,就像直接在单元格中键入一样 我有一张像这样的桌子: AA BB CC -------------- 1 aa ac 2 bb fd// I type here and change the value to kk 代码: 我是否应该使用DataGridViewTextBoxEditingControl?执行此操作(假设您希望以编程方式更改一个值): 并且已经解释了如何启用
AA BB CC
--------------
1 aa ac
2 bb fd// I type here and change the value to kk
代码:
我是否应该使用DataGridViewTextBoxEditingControl
?执行此操作(假设您希望以编程方式更改一个值):
并且已经解释了如何启用对特定单元格的编辑。如果要将数据源设置为对象,则链接到特定字段的属性必须具有setter才能更改值。否则,它将被视为只读属性。不确定这是否有帮助,有点不清楚你在追求什么,你在使用什么。
public void UpdateDataGridView(int-cindex,字符串值)
public void UpdateDataGridView(int cindex, string value)
{
if (InvokeRequired)
{
this.Invoke(new Action<int,string>(UpdateDataGridView), new object[] { cindex, value });
return;
}
int selectedRowIndex = dataGridView1.SelectedRows[0].Index;
dataGridView1.Rows[selectedRowIndex].Cells[cindex].Value = value;
}
{
如果(需要调用)
{
Invoke(新操作(UpdateDataGridView),新对象[]{cindex,value});
返回;
}
int selectedRowIndex=dataGridView1.SelectedRows[0]。索引;
dataGridView1.Rows[selectedRowIndex]。单元格[cindex]。Value=Value;
}
我想直接在Windows中更改Forms@UniLe这有帮助吗?:)是的,你的回答是正确的。它刚刚读取了属性。如何更改可以在其中读写的数据源?如果使用自定义对象作为数据源,则相关属性需要有一个setter方法public PropertyName{get;set;}如果没有setter,数据绑定无法更新绑定对象中的值不清楚要做什么,或者什么不起作用。是否希望能够在网格上的单元格中键入内容?这应该行得通。当你尝试时会发生什么?对不起,我没有解释得太清楚。多亏了Vyktor,我知道要编辑单元格,我应该编写dataGridView1.BeginEdit(true);谢谢大家
dataGridView1.Rows[RowNumber].Cells[CC.Index].Value = newValue;
// Retrieve the cell value for the cell in the Name column at row 4.
String testValue2 = (String)dataGridView1["Name", 4].Value;
public void UpdateDataGridView(int cindex, string value)
{
if (InvokeRequired)
{
this.Invoke(new Action<int,string>(UpdateDataGridView), new object[] { cindex, value });
return;
}
int selectedRowIndex = dataGridView1.SelectedRows[0].Index;
dataGridView1.Rows[selectedRowIndex].Cells[cindex].Value = value;
}