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

Checkbox row selection in gridgroupingcontrol, continually adding rows.

Hi,

I've been running into an error when trying to do checkbox row selection with the gridgroupingcontrol.

I've based my code off of thishttp://www.syncfusion.com/forums/105749/Check-box-for-row-selection-in-grid-grouping-control

While this works when the datatable is not changing when I am adding rows to the datatable the checkbox selection is incorrect, sometimes the checkboxes get unchecked or moved.

I will attach a video showing the offending behaviour. (Sorry the video goes on about 20 seconds too long )

I have also attached some code showing you how rows is added and how i'm handling checkboxes

(dmTable is a DataTable)

//partial code
{..
this.gridGroupingControl1.DataSource = this.dmTable;
//Disallow Editing
this.gridGroupingControl1.ActivateCurrentCellBehavior = GridCellActivateAction.None;
this.gridGroupingControl1.TopLevelGroupOptions.ShowAddNewRecordBeforeDetails = false;
#region Checkbox Settings
this.gridGroupingControl1.TableControlCheckBoxClick += new Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlCellClickEventHandler(gridGroupingControl1_TableControlCheckBoxClick);
#endregion
..}
{..
System.Data.DataRow row = this.dmTable.NewRow();
row[COL_SDE] = sde;
row["Select"] = checkBoxValue[1];
row[COL_Imported] = string.Empty;
row[COL_Date] = sde.GetDate();
foreach (string seriesName in seriesNames)
{
row[seriesName] = sde.GetValue(seriesName);
}
// add row to the table
this.dmTable.Rows.InsertAt(row, 0);

...}

void gridGroupingControl1_TableControlCheckBoxClick(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlCellClickEventArgs e)
{
Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfo style = (Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfo)e.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex, e.Inner.ColIndex);
Record currentRecord = style.TableCellIdentity.DisplayElement.GetRecord();
// Selection added for current record
if (this.gridGroupingControl1.TableModel[e.Inner.RowIndex, e.Inner.ColIndex].Text == "False")
currentRecord.SetSelected(style.Text == "False");
}
anyway wondering if i'm doing something wrong or if syncfusion can not handle it.

Attachment: Syncfusionvideo_83efcf81.zip

5 Replies

AK Adhikesevan Kothandaraman Syncfusion Team May 23, 2016 10:31 AM UTC

Hi James, 

Thanks for using Syncfusion products. 

To Set the record based on the selection on the check box column, Change the conditions given in the TableControlCheckBoxClick event as of follows, 

Code Snippet: 
this.gridGroupingControl1.TableControlCheckBoxClick += new GridTableControlCellClickEventHandler(gridGroupingControl1_TableControlCheckBoxClick); 
void gridGroupingControl1_TableControlCheckBoxClick(object sender, GridTableControlCellClickEventArgs e) 
{ 
    GridTableCellStyleInfo style = (GridTableCellStyleInfo)e.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex, e.Inner.ColIndex); 
    Record currentRecord = style.TableCellIdentity.DisplayElement.GetRecord(); 
    currentRecord.SetSelected(style.Text == "False"); 
} 
  
Sample Link: 
 
Regards, 
Adhi  



JA James May 23, 2016 12:18 PM UTC

I'm still running into an error like in the video, either the checkbox is moving or it's selecting something i'm not selecting, i'll upload another video.


Also the link you sent me also doesnt continually add rows like my version. Anyway you could get a version to continually add rows? Or can syncfusion not handle it, and the checkbox selection.




Attachment: syncvideo2_be2f6307.zip


AK Adhikesevan Kothandaraman Syncfusion Team May 24, 2016 03:08 PM UTC

Hi James, 

Thanks for your update. 

We have tried to replicate the scenario with adding more number of rows in with the check box selection. Since the selection is made on the row index, the added row index collapses the selection.  
As a suggestion use the condition in the QueryCellInfo instead of the TableControCheckBoxClick event.  

Regards, 
Adhi 



JA James May 24, 2016 07:47 PM UTC

Hey, 

Is there any examples doing something like this?, new to this controller.
Should I be using QueryCellInfo, or QueryCellStyleInfo?

Thank you,

James


AK Adhikesevan Kothandaraman Syncfusion Team May 25, 2016 02:42 PM UTC

Hi James, 

Regret for the inconvenience caused. 

The reported scenario can be achieved by using QueryCellStyleInfo event with certain limitation. The selection can be added based on the checkbox value only on the grid is in static mode.  
When adding the new rows, you can select the checkbox values. The grid will update selected records at the end of the update. Please refer to the following code snippet, 

Code Snippet: 
 
//Set to true only on adding the new rows 
bool updating = false; 
this.gridGroupingControl1.QueryCellStyleInfo += new GridTableCellStyleInfoEventHandler(gridGroupingControl1_QueryCellStyleInfo); 
 
void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e) 
{ 
    if(e.Style.CellType == GridCellTypeName.CheckBox && !updating ) 
    { 
        e.Style.TableCellIdentity.DisplayElement.GetRecord().SetSelected(e.Style.Text == "True"); 
    }             
} 
 
Sample Link: 

Regards, 
Adhi 


Loader.
Up arrow icon