WPF - DataGrid - Deletion

5

How can I get the index of a selected item in my DataGrid in WPF?

I know that in WEB Forms I can get it like this:

MainGrid.Rows[e.RowIndex].Cells[0].Text
    
asked by anonymous 14.04.2014 / 20:09

3 answers

2

Try this.

foreach (var item in MainGrid.SelectedItems)
{
     this.SelectedProducts.Add((B.Product)item);
}
    
14.04.2014 / 20:56
0

If I did not get it wrong ...

MainGrid.SelectedIndex
    
05.01.2017 / 14:23
0

If you want to get the value of a selected item and store it in an attribute, try this example:

Usuario u = new Usuario();
u = DataGrid.SelectedItem as Usuario;
string nome = u.nome;
    
05.06.2018 / 00:31