Get the multiple selected Row in data-grid in WPF?

13,507

Solution 1

I have got a solution for the above question,

//CustomerDTO is the DTO class which has all the column names of Customer Table.
//dgUsers is the data grid.
List<CustomerDTO> customerList ;
for (int i = 0; i < dgUsers.SelectedItems.Count; i++)
{
customerList.Add((CustomerDTO)dgUsers.SelectedItems[i]);
}

Thanks.

Solution 2

There are many stackoverflow posts concerning this problem. Following are two posts which describe how to get the selected items.

Code behind approach: DataGrid get selected rows' column values

MVVM approach: Bind to SelectedItems from DataGrid

Share:
13,507
Murtaza Badshah
Author by

Murtaza Badshah

Updated on June 04, 2022

Comments

  • Murtaza Badshah
    Murtaza Badshah almost 2 years

    I want to get the multiple selection of data-grid in WPF, as my the business requirement I have a customer table in data grid which allows multiple selection and radio button (ALL, Selected, All but selected). If the selected or all but selected is clicked the I have to pull data only for those customers which are selected in the data- grid. Please advice solution to get multiple selected row of data grid.

    Thanks.

  • NEBEZ
    NEBEZ over 3 years
    and for remove item from list : var unSelected = grdItems.SelectedItem as Class; list.Remove(unSelected); if used check box Un_Checked event.