DataGrid selecting rows

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

My task is a little more complicated than that because of my user
requirements. In my app I have made the DataGrid read only because there is
concern that the users will inadvertently delete rows. I need the Delete to
be a two-step process in which the user selects rows on the datagrid and then
clicks a button to confirm that the selected rows will be deleted.

So, my challenge is just to identify the rows that are selected and then
pass these rows to a procedure for deletion. I thought I could do this with
the IsSelected property but it doesn't seem to be working.
 
Hi Gary,

When you select a row in a datagrid, it is possible to find it's actual
location in the datatable by using the bindingcontext, regardless of the sort
applied in the grid.

But in your case, you need the opposite requirement. When you use the
IsSelected method, you need to pass the row index of the row in the grid. But
ASAIK there is no straightforward method to find out the location of a row in
a grid if you know the actual location of the row in the underlying binding.

One workaround will be to add a hidden column in the Datatable with
incremental values with respect to the current data sort. Whenever the sort
changes, you will have to update the column values.

When you select multiple rows and press the delete button, you could find
out the datarow by using the row's primary key. And you could pass the
IsSelected method the index by obtaining the index value from our new column.

Let me know if I could be of more assistance.

HTH,
Rakesh Rajan
 
Back
Top