如何将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");
             }

           }

      }

您已经发现,WPF DataGrid没有Rows属性

尝试这样的操作:
As you have discovered, the WPF DataGrid does not have a Rows 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