2012-10-08 29 views
2

如何更改DataGridView Windows窗体中所有单元格的值?我想直接在Windows窗体改变,就像直接在单元格直接在DataGridView中更改值

打字我有这样一个表:

AA BB CC 
-------------- 
1  aa ac 
2  bb fd// I type here and change the value to kk 

代码:

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}; 

我应该做DataGridViewTextBoxEditingControl什么?

+0

目前尚不清楚你想要做什么,或者什么不能工作。你想能够输入网格中的单元格吗?这应该只是工作。当你尝试时会发生什么? –

+0

对不起,我没有太清楚地解释它。感谢Vyktor我知道,编辑单元格我应该写dataGridView1.BeginEdit(true);感谢所有人 –

回答

4

(要改变编程一个值假设),你可以简单地这样做:

dataGridView1.Rows[RowNumber].Cells[CC.Index].Value = newValue; 

而如何使某些细胞的编辑进行了说明here

+0

我想直接在Windows窗体中更改 –

+0

@UniLe http://stackoverflow.com/questions/1814423/datagridview-how-to-set-a-cell-in-editing-mode is'n this helps? :) – Vyktor

+0

是的,非常感谢:) –

0
// Retrieve the cell value for the cell in the Name column at row 4. 
String testValue2 = (String)dataGridView1["Name", 4].Value; 
1

如果您的数据源设置为一个对象,然后链接到某一个领域的财产必须有一个setter,以改变数值。否则,它是一个只读属性,将被视为这样。不知道这是否有帮助,它有点不清楚你在做什么,以及你在做什么。

+0

是的,你是正确的。它刚刚阅读过财产。我怎样才能改变我可以在那里读写的数据源? –

+0

如果您使用自定义对象作为数据源,则所涉及的属性需要使用setter方法 public PropertyName {get;组; } 没有setter,数据绑定无法更新绑定对象中的值 – Wanabrutbeer

相关问题