3

我在虚拟模式下有一个 DataGridView。我只实现了如http://msdn.microsoft.com/en-us/library/15a31akc.aspx中所述的 CellValueNeeded 事件处理程序。

仅当您希望能够手动编辑单元格时,似乎才需要实现其余事件。

我想以编程方式编辑 DataGridView 单元格值。

我使用以下代码进行了尝试:

DataGridView1.EditMode = DataGridViewEditMode.EditProgrammatically;
DataGridView1.BeginEdit(false);
DataGridView1.Rows[0].Cells[0].Value = "testing new value";
//just using a random parameter here, not sure it is needed when editing programmatically
DataGridView1.CommitEdit(DataGridViewDataErrorContexts.LeaveControl);
DataGridView1.Refresh();

但没有成功:(

任何帮助,将不胜感激

4

1 回答 1

7

当您使用虚拟模式时,您可以提供自己的逻辑来链接DataGridView到底层数据源。因此,要编辑单元格值,您应该更改底层数据源中的值,并调用Refresh以刷新显示的值(这将导致CellValueNeeded为所有显示的单元格调用事件)

于 2009-10-11T20:16:15.263 回答