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

GGC record insertion

I have discovered a strange case regarding row insertion to a DataTable and these rows being drawn to the grid.

When inserting records into a DataTable that is set as the DataSource of the GridGroupingControl, sometimes the rows are not drawn to the grid even through they are inserted into the DataTable.

I wrote a small sample using a GGC straight out the box, no optimizations were applied and all properties were left with their default values. I then bound a DataTable to the grid and attempted to insert rows into the table.

I used the following cases:
Case 1:
An object array is build with the row values and then inserted into the table using LoadDataRow(). When this method is used with an empty table, the first row is drawn when inserted, but any rows following this are not drawn to the grid despite existing in the DataTable.

Case 2:
An object array is built and then inserted using table.Rows.Add(object[]). The results from this are the same as the previous method.

Case 3:
A DataRow object is created by calling table.NewRow(). This DataRow is then filled with values and inserted using table.Rows.Add(DataRow). When this method is used, all rows are drawn when inserted. This appears to work correctly.


I have attached a sample that demonstrates this problem.



SyncfusionGroupingGridTest_75e1d68b.zip

12 Replies

RK Ranjeet Kumar Syncfusion Team December 3, 2009 01:53 PM UTC

Hi Mike,
Thanks for using Syncfusion Products.

With respect to case 1 and 2 , To be able to insert the new record into GridGroupingControl and subsequently display them, you need to set the TableDirty property to true and then refresh the grid. the same has been shown using the codes in the sample provided by you.


// When a table is marked dirty, the subsequent access of its elements will trigger the recategorization of the of all records in the table.

ggc.Table.TableDirty = true;

// this will redraw the parent control and any child control
ggc.Refresh();




Please find the sample from the following link in which this code has been implemented.

http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=SyncfusionGroupingGridTest1113763587.zip

Please, do let me know if you have any query.


Regards
Ranjeet


MM Mike Mann December 3, 2009 02:24 PM UTC

Can you provide an explanation on why this is the case? I have tested this example using your non-grouping Databound grid and all of the methods for loading data work without having to explicitly tell the grid the datasource is dirty. Is there a reason for this difference in functionality?


MM Mike Mann December 3, 2009 09:21 PM UTC

Another issue that this has brought up. When calling Refresh() on the grid, selected rows become unselected. I need selected rows to remain selected when new rows are being inserted.


RK Ranjeet Kumar Syncfusion Team December 8, 2009 01:47 PM UTC

Hi Mike,

Thanks for using Syncfusion Products.

To keep the selected rows remain selected when new rows are being inserted, you need to set ListBoxSelectionMode to MultiExtended and

AllowSelection to Any as shown below in the code snippets provided :



\\ Defines selection behavior of a grid

this.grid.TableOptions.AllowSelection = GridSelectionFlags.Row | GridSelectionFlags.Multiple;



Towards the response to your previous post, we need to explicitly mark the table as dirty so as to trigger the recategorization of the records and finally refresh the grid to redraw the client area.
Please find the sample from the following link in which this code has been implemented.

http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=AllowCalculateMaxColumnWidth_In_GGC-581107751.zip

Please, do let me know if you have any query.

Regards
Ranjeet


MM Mike Mann December 8, 2009 02:45 PM UTC

Setting these selection properties does not work as intended. With AllowSelection and ListBoxSelectionMode set, the selection does not disappear like in the previous case, but it doesn't move with the inserts. If the records are sorted and new records come in before the current selected records, these new records will be selected instead of the previous ones. In addition, when sorting columns the selection will not move based on the sort, so different records will end up being selected when sorting. I require the selection to be associated with the actual records and not simply the position in the grid.

Selection shifting appears to work correctly when you do not set TableDirty = true, but it looks like the grid is far less performant when inserting records. I need a way to insert a very high volume of inserts and updates, while keeping the grid performant and keeping selection intact.


LS Lingaraj S Syncfusion Team December 9, 2009 02:28 PM UTC

Hi Mike,

Thank you for the update.

Try using below way to select the Record in GridGroupingControl, Also it is not affected the selection in GridGroupingControl when Table.TableDirty property and Refresh method is used to update underlying data source value.

Refer the code below:

this.grid.TableOptions.AllowSelection = GridSelectionFlags.None;
this.grid.TableOptions.ListBoxSelectionMode = SelectionMode.One;


Refer the sample from below link, Also I have attached the one video file in below link, it shows which I tried in GridGroupingControl.
http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=Sample1234580588.zip

Please have look at the above modified sample and let me know if you still face the issue. Please try to reproduce the issue in above sample or send the reproducing sample to analyze the behavior and give a better solution.

Regards,
Lingaraj S.


MM Mike Mann December 9, 2009 02:51 PM UTC

This does not meet my requirements. The code you have posted allows only one row to be selected at a time. I need to be able to select multiple rows and still have all of them move correctly when sorting or inserting records.


LS Lingaraj S Syncfusion Team December 9, 2009 02:58 PM UTC

Hi Mike,

Thank you for the update.

Please try using below setting in GridGroupingControl to select the multiple records.

Refer the code below:

this.grid.TableOptions.AllowSelection = GridSelectionFlags.None;
this.grid.TableOptions.ListBoxSelectionMode = SelectionMode.MultiExtended;


Please let me know if you have any queries.

Regards,
Lingaraj S.


MM Mike Mann December 9, 2009 03:26 PM UTC

I have already tried using that specific combination of properties. I suppose I should provide some more information:

I am trying to do a batch insert of 100 records. I am generating the rows using a BackgroundWorker and then adding this data to my datatable. The insertion of records is wrapped with calls to grid.BeginUpdate() followed by table.BeginLoadData(). The corresponding End calls are made after the insertion is completed. This is followed by a call to grid.Refresh(). This appears to work without using the TableDirty property, however it also appears to be less performant.

The problem starts when the TableDirty property is set to true. Assuming ListBoxSelectionMode.MultiExtended is required and AllowSelection is set to None. If the VirtualMode engine optimization is used, calls to Refresh() will cause the selection to be removed. If you are not using the VirtualMode optimization, a call to Refresh() will cause the selection to remain painted on the grid even when a new row is selected. The only way to remove this painted selection is to reselect the area and then remove the selection before another call to Refresh() is made.

Using the other selection mode (Not ListBoxSelection) has its own share of problems. Since this mode of selection is row based and not record based, the selection tends to stay in the same relative spot and not move with the selected data.


LS Lingaraj S Syncfusion Team December 10, 2009 01:41 PM UTC

Hi Mike,

Thank you for the update.

Please try using SetSelected method in Record after insertion to achieve your requirement as shown below:

List selRecCol = new List();
foreach (SelectedRecord selRec in this.gridGroupingControl1.Table.SelectedRecords)
{
selRecCol.Add(selRec.Record);
}
// Please try using your Record insertion
foreach (Record rec in selRecCol)
{
rec.SetSelected(true);
}


Please let me know if you still face the issue. Try to send a minimal sample to achieve your requirement earliest.

Regards,
Lingaraj S


RB Ron Baron October 22, 2010 10:47 PM UTC

Is there any update on this issue?
IMO selection moving with the record should be the default behavior.
Also, the last post does not provide a workable solution since it places a grid dependency in the business logic.



NR Nirmal Raja Syncfusion Team November 8, 2010 08:39 AM UTC

Hi Ron,

Sorry for the delay.

For the dynamic selection of the grid rows please refer the sample attached in the below location:
http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=DeleteRecord45616542.zip

Let me know if this meets your requirement, else provide us a sample that reproduces the issue.

Regards,
Nirmal


Loader.
Live Chat Icon For mobile
Up arrow icon