我有一個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