我有一个DataGridView绑定到一个对象数组。获取与DataGridView中选定行关联的对象
List<Node> nodes = GetNodeList();
m_grid.DataSource = nodes;
然后我处理SelectionChanged事件。
在SelectionChanged事件的处理程序中,我想访问选定的对象。
我似乎能够做的就是访问网格中每个单元格的值,而不是与该行相关的整个对象。
void OnSelectionChanged(object sender, EventArgs e)
{
foreach (DataViewGridRow row in m_grid.SelectedRows)
{
/* Here I want to be able to access the Node object associated with this row*/
}
}
我相信它一定是可能的,但我无法弄清楚。我可以得到行索引,然后回头看看数组,但看起来有点哈克。
细胞的类型是一个不好的名字一排 – 2011-02-23 12:22:10
非常真实 - 我会编辑它。 – Nick 2011-02-23 12:26:44