Datagrid Multi Row Select???

  • Thread starter Thread starter Darryn Ross
  • Start date Start date
D

Darryn Ross

Hi,

I need to delete all the selected records from a Datagrid, but i cannot seem
to work out how from code you can tell what records are selected in order to
build my adapter delete command?

Any help would be great.

thanks

Darryn
 
Hi,

Assuming we're speaking about the WinForms DataGrid:

Short answer: iterate on all row indexes and call IsSelected(rowNum) on each
grid row. Can have detrimental effect on performance.
Long answer: create an inherited control and provide your own tracking of
selected rows. This way, you'll always have a set of rows currently selected
so you won't have to iterate.
 
Add a Template column with a checkbox, and when the user
selects the checkboxes do the following

//put the code in a button click
foreach(DataGridItem dgi in myGrid.Items)
{
CheckBox c = (CheckBox)dgi.FindControl
("selectionCheckBox");
if(c.Checked)
{
//add row for deletion
}

hope this helps
 
Back
Top