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
close icon

Retrieving DataRow from Grouped grid checkbox-click

Hello, I am trying to use a Grouping grid to display records that contain CheckBoxes. I have been able to create and display the data, but now I want to be able to get the current row information, from the ''clicked'' checkbox''s row. I can use the ''grid.TableControlCheckBoxClick'' to create an event and retrieve a row index from ''e.Inner.RowIndex'', but this is the incorrect index for the datasource. This is the index of the grid. I can get an index by making a copy of the table and comparing them after the event checkboxclick event has happened. Although I need to use a timer to cause a slight delay in order for the event to actually be triggered and the source data updated. I want to be able to get either the whole row of data or the index (for the data source) to access this record, when the checkbox has been ''clicked''. Any idea''s how I can access the ''selected'' row’s data?? Thanks. David.

7 Replies

AD Administrator Syncfusion Team September 13, 2004 12:43 PM UTC

Maybe code like this will work for you.
private void gridGroupingControl1_TableControlCheckBoxClick(object sender, GridTableControlCellClickEventArgs e)
{
	GridRecordRow rec = this.gridGroupingControl1.Table.DisplayElements[e.Inner.RowIndex] as GridRecordRow;
	if(rec != null)
	{
		DataRowView dr = rec.GetData() as DataRowView;
		Console.WriteLine(dr["Col1"]); //some column
	}
}


DL David Llewellyn September 13, 2004 11:53 PM UTC

Thank you. This code works fine to retrieve the record. BUT it returns the unmodified datarow, as if the CheckBoxClick event has not yet happened. I tried to manually set the checkbox value to true. eg:- table.Rows[recordindex][colindex] = true; But this causes additional events to be triggered and some strange effects happen. I could use a timer to allow the checkboxclick event to actually take place before trying to access that specific record, but I don’t want to rely on timers for this. Is there some other event that I could use which will allow me to access the modified and updated record that has just been ''clicked''??? Or is there a way to modify this record in the datatable, without causing additional messages to be triggered??? Thanks. David.


AD Administrator Syncfusion Team September 14, 2004 06:24 AM UTC

I take it that knowing the bool value is the opposite of teh value you are currently getting is not sufficient for your needs? Anyway, one thing you can to is to explicitly change it your self and cancel the event so the grid does not reset it as part of its normal processing.
private void gridGroupingControl1_TableControlCheckBoxClick(object sender, GridTableControlCellClickEventArgs e)
{
	GridRecordRow rec = this.gridGroupingControl1.Table.DisplayElements[e.Inner.RowIndex] as GridRecordRow;
	if(rec != null)
	{
		DataRowView dr = rec.GetData() as DataRowView;
		dr["bool"] = ! (bool) dr["bool"];
		dr.EndEdit(); //maybe???
		e.Inner.Cancel = true;
		Console.WriteLine(dr["bool"]);
	}
}


DL David Llewellyn September 14, 2004 08:18 PM UTC

Thank you for your help. This code is exactly what I needed to solve my problem. Thanks again.


SK Sameer Khan January 13, 2009 01:41 PM UTC

Is there a way to get the check box change event on a cell of a GridGroupingControl?

TableControlCheckBoxClick is only fired if the user uses a mouse to click on the check box; but not when the user uses the space bar to change the check status.





SK Sameer Khan January 13, 2009 04:00 PM UTC

Handling the Key up event and checking for the Space Key worked.

-S



NA Nisha Arockiya A Syncfusion Team January 15, 2009 06:37 AM UTC

Hi Sameer,

Thanks for sharing information with us.

Please let us know any other concerns.

Regards,
Nisha.


Loader.
Live Chat Icon For mobile
Up arrow icon