【发布时间】:2014-12-02 23:37:50
【问题描述】:
这里我使用datagridview中的代码,它工作正常。但是如何在不选择wpf中datagrid中的行的情况下获取datagrid中的rowindex。请帮我做。 下面的代码我试过了:
private int GetRowIndex(string ID)
{
int num = -1;
//Get the row based on ID
foreach (DataGridViewRow dataGridVV in (IEnumerable)this.dataGridView.Cells)
{
if (dataGridVV.Cells[0].Value.Equals((object)ID))
num = dataGridVV.Index;
}
return num;
}
【问题讨论】:
-
为什么在 wpf 中需要行索引?
-
使用 SelectedItem 和/或 SelectedIndex 属性有什么问题?
-
您不应该使用 WinForms 样式的 WPF。使用绑定集合,而不是
DataGrid。 -
你的 ItemsSource 应该指向一个 ObservableCollection,然后你所要做的就是在那里删除它。
-
正如@HenkHolterman 已经说过的,从
ItemsSource中删除该项目。
标签: c# .net wpf datagridview datagrid