We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

GridGroupingControl - SelectedRecords

Hi,

I have a GGC, that is binded to a datatable. user can add, edit, delete records. No parent-child records.

What I need to do is to enable the user to select 1 or more rows by clicking and dragging the mouse on the rows header. this hilights the rows with black color-which is fine.
Then the user should click a button (Delete) to delete the hilighted rows.

Thanks for your help.


3 Replies

AA Arulraj A Syncfusion Team January 3, 2019 11:26 AM UTC

Hi Loai, 

Thanks for using Syncfusion product. 

To delete the selected records, use the ListBoxSelectionMode to MultiExtended and call the Table.SelectedRecords.DeleteAll method. 

this.gridGroupingControl1.TableOptions.ListBoxSelectionMode = SelectionMode.MultiExtended; 


private void button1_Click(object sender, EventArgs e) 
{ 
    this.gridGroupingControl1.Table.SelectedRecords.DeleteAll(); 
} 
 


Arulraj A 



LO Loai January 3, 2019 11:46 AM UTC

Hi,

Using ListBoxSelectionModewill give a different user experience. As the records will always be selected whenever the user clicks on any row. Is it possible to select the row(s) only when the user select them by using the row header?


AA Arulraj A Syncfusion Team January 3, 2019 12:43 PM UTC

Hi Loai,  

Thanks for the update.  

To delete the selected records using AllowSelection, use the Row flag to select the row using its header and use the TableControl.Selections.GetSelectedRows method and delete the records manually from bottom to up.  

this.gridGroupingControl1.TableOptions.AllowSelection = GridSelectionFlags.Row; 
 
private void button1_Click(object sender, EventArgs e) 
{ 
    var range = this.gridGroupingControl1.TableControl.Selections.GetSelectedRows(true,true); 
 
    foreach (GridRangeInfo info in range) 
    { 
        for (int i = info.Bottom; i >= info.Top; i--) 
        { 
            Element el = this.gridGroupingControl1.TableModel.GetDisplayElementAt(i); 
            Console.WriteLine("Selected RowIndex : " + info.Top + " =====> " + el); 
            el.GetRecord().Delete(); 
        } 
    } 
    this.gridGroupingControl1.TableControl.Selections.Clear(); 
} 
 
  
Arulraj A  


Loader.
Up arrow icon