Deleting Row when grouping

I am trying to delete a row when the list is a grouping set. I noticed the RemoveAt() works completely fine for when its not group, but when the list is grouped with a Key, it cannot delete in the view. My list is changing, but the view doesn't reflect the changes.

I used the Clear grouping then grouped it again, but this isn't the feature I wanted as it collapses all the opened groups prior. 

        private void sfButton1_Click(object sender, EventArgs e)
        {
            var workloadObj = sfDataGrid1.View.AddNew() as WorkloadGrid;

            workloadObj.Project = "HIHI";
            workloadObj.number1 = 1;
            workloadGridViewList.Add(workloadObj);
            sfDataGrid1.View.CommitNew();

        }

        private void Form1_Load(object snder, EventArgs e)
        {
            for (var i = 0; i < 5; i++)
            {
                WorkloadGrid workloadObji = new WorkloadGrid();
                workloadObji.Project = i.ToString() ;
                workloadObji.number1 = i;
                workloadGridViewList.Add(workloadObji);

            }

            sfDataGrid1.DataSource = workloadGridViewList.ToList();

        }

        private void sfButton2_Click(object sender, EventArgs e)
        {
            sfDataGrid1.View.RemoveAt(0);
        }

Attachment: WindowsFormsApp1_942c86e7.rar

3 Replies 1 reply marked as answer

BR bracknelson March 10, 2021 05:40 AM UTC

Choose "Data" from the top menu bar, and next click "Outline" to ungroup rows via the Subtotal function. Select "Subtotal" from the menu to bring up a dialog box with selections. Click on the "Remove All" button to eliminate the grouping.


JU Julius March 10, 2021 05:54 AM UTC

I'm not sure I understand what you mean. In the accessibileRole I changed it from Default to Outline, but I don't see anything about "subtotal". 

I don't want to remove the grouping, but I want to remove a data entry row that I added in the grouped list.


VS Vijayarasan Sivanandham Syncfusion Team March 11, 2021 03:10 PM UTC

Hi Julius,

Thank you for contacting Syncfusion support. 
By default, In SfDataGrid you can delete the selected row by pressing the Delete key when the SfDataGrid.AllowDeleting property is set to true. Please refer the below user documentation for more details,

UG Link:
https://help.syncfusion.com/windowsforms/datagrid/datamanipulation#delete-row

We have analyzed your provided sample. You can delete the row while grouping case also using underline collection in SfDataGrid. Here, workloadGridViewList is the List type while removing the record using index it will not reflect in SfDataGrid. Because the List collection does not implements INotifyCollectionChanged interface. So, SfDataGrid will not refresh the UI automatically.

For more information, please refer the below UG link, 
You can resolve the issue by using ObservableCollection  as dataSource in SfDataGrid. Please refer the below code snippet for your reference, 
//Change the collection type list to ObservableCollection   
ObservableCollection<WorkloadGrid> workloadGridViewList = new ObservableCollection<WorkloadGrid>(); 

In your provided sample workloadGridViewList is the collection and having the records for SfDataGrid.DataSource. You can achieve your requirement to delete or remove a row from the collection(workloadGridViewList)by passing the row index.  Please refer the below code snippet for your reference, 
private void sfButton2_Click(object sender, EventArgs e) 
 {  
            //remove the record at index while grouping 
            workloadGridViewList.RemoveAt(0);            
 } 
Please let us know, if you require further assistance on this.

Regards,
Vijayarasan S 


Marked as answer
Loader.
Up arrow icon