Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I want to convert this code to WPF

Thank you for any help :)

What I have tried:

C#
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");
             }

           }

      }
Posted
Updated 12-May-17 5:44am
v4
Comments
Richard MacCutchan 12-May-17 9:18am    
If your WPF app uses C# then there is nothing to convert.
[no name] 12-May-17 9:21am    
Except, why are you converting a string to a string? Does that really make sense to you?
EM_Y 12-May-17 9:45am    
Thank you It's tap mistake ,I fixed that ! :)
[no name] 12-May-17 9:56am    
FYI C# in WPF is exactly the same C# that is in Winforms. You need to explain your problem better.
EM_Y 12-May-17 11:45am    
I've just updated my code , I wish it's more clear

1 solution

As you have discovered, the WPF DataGrid does not have a Rows property

Try something like this:
C#
foreach (System.Data.DataRowView dr in datagrid.ItemsSource)
{
    string t = dr[3].ToString();
    if (t =="research_Key")
    {
        MesssageBox.Show("ok");
    }
}

But as @Richard-MacCutchan pointed out - t will only be the string from the last row in the DataGrid
 
Share this answer
 
v2
Comments
EM_Y 12-May-17 11:40am    
t could be the string from any row in data grid ; I've just updated my code , I wish it's more clear
CHill60 12-May-17 12:26pm    
I've updated my solution to reflect your code changes
EM_Y 15-May-17 3:32am    
your genius :p , thank you for help ^^

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900