如何将datagridview行数从Windows窗体应用程序转换为WPF应用程序
问题描述:
我想将此代码转换为WPF
谢谢您的帮助:)
我尝试过的事情:
I want to convert this code to WPF
Thank you for any help :)
What I have tried:
private void button_Click(object sender, KeyEventArgs e)
{
for (int i = 0; i < datagrid.row.Count - 1; i++)
{
string t = Convert.ToString(datagrid.Rows[i].Cells[3].Value);
if (t =="research_Key")
{
MesssageBox.Show("ok");
}
}
}
答
您已经发现,WPFDataGrid
没有Rows
属性
尝试这样的操作:
As you have discovered, the WPFDataGrid
does not have aRows
property
Try something like this:
foreach (System.Data.DataRowView dr in datagrid.ItemsSource)
{
string t = dr[3].ToString();
if (t =="research_Key")
{
MesssageBox.Show("ok");
}
}
但是正如@ Richard-MacCutchan指出的那样-t
只会是DataGrid中最后一行的字符串
But as @Richard-MacCutchan pointed out - t
will only be the string from the last row in the DataGrid