WPF - Datagrid - Exclusion

Asked

Viewed 266 times

5

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

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

MainGrid.Rows[e.RowIndex].Cells[0].Text

3 answers

2


Try this.

foreach (var item in MainGrid.SelectedItems)
{
     this.SelectedProducts.Add((B.Product)item);
}

0

If I didn’t get it wrong...

MainGrid.SelectedIndex

0

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

Usuario u = new Usuario();
u = DataGrid.SelectedItem as Usuario;
string nome = u.nome;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.