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

ReadOnly GridDataBoundGrid

I''m trying to set a row readonly based on a boolean value of a column in my grid i''ve tried prepareviewsytle event and i''ve tried QueryCellInfo. Below is an example of the code I tried. It seems that trying to access cells outside the one that the event is firing on causes the grid to become unstable. private void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e) { if(e.ColIndex == 1 && this.gdgMessages[e.RowIndex, 1].CellValue.ToString() == "TRUE") { e.Style.ReadOnly = true; if(e.ColIndex == 4 || e.ColIndex == 5) { // Remove the date time picker e.Style.CellType = "TextBox"; } } } Could anybody suggest a way to dynamically set rows readonly based on this criteria? Cheers

4 Replies

AD Administrator Syncfusion Team November 18, 2005 04:53 PM UTC

QueryCellInfo is the proper place to do this. You need to set the value for all the columns, not just e.ColIndex == 1. So try code like: if(e.ColIndex > 1 && this.gdgMessages[e.RowIndex, 1].CellValue.ToString() == "TRUE") You also have to make sure that this.gdgMessages[e.RowIndex, 1].CellValue.ToString() has the value "TRUE" and not "true" (for example). If this is a column of type bool, you can try testing ((bool)this.gdgMessages[e.RowIndex, 1].CellValue) which should be a boolean value unless it is null or DBNull. If you also want to include column 1 in setting ReadOnly, then you should have a special case for column 1 since it is your test column. When e.ColIndex == 1, then test e.Style.Cellvalue instead of indexing the grid to get the cell value.


MN Mike N November 18, 2005 06:21 PM UTC

Thanks for the suggestions but they didn''t seem to resolve the issue. It appears that accessing an index of the grid outside the event is causing some kind of infinite loop. Which promptly causes the grid to become unstable and display that pretty red X. this.gdgMessages[e.RowIndex, 1].CellValue.ToString() == "TRUE") If I remove that line all is well. Could there be something i''m missing? Thx


MN Mike N November 18, 2005 06:48 PM UTC

I managed to find a work around though it''s rather discusting. private void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e) { this.gdgMessages.Model.QueryCellInfo -= new GridQueryCellInfoEventHandler(Model_QueryCellInfo); if(e.ColIndex > 0 && this.gdgMessages[e.RowIndex,2].CellValue.ToString() == "TRUE") { e.Style.ReadOnly = true; if(e.ColIndex == 4 || e.ColIndex == 5) { //Remove the date time picker e.Style.CellType = "TextBox"; } } this.gdgMessages.Model.QueryCellInfo += new GridQueryCellInfoEventHandler(Model_QueryCellInfo); } } Checking a value of a cell value outside the current cells event was causing another querycellinfo event to fire which ultimately was causing an infinite loop. Is there perhaps a more elegant solution that removing the event handler everytime I check a different cells value? Mike


AD Administrator Syncfusion Team November 18, 2005 10:29 PM UTC

Try this code.
private void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{ 
	if((e.ColIndex == 2 && e.Style.CellValue.ToString() == "TRUE") ||
   		((e.ColIndex == 1 || e.ColIndex > 2) 
		   && this.gdgMessages[e.RowIndex,2].CellValue.ToString() == "TRUE"))
	{
		e.Style.ReadOnly = true;
		if(e.ColIndex == 4 || e.ColIndex == 5)
		{
			//Remove the date time picker
			e.Style.CellType = "TextBox";
		}
	}
 
}

Loader.
Live Chat Icon For mobile
Up arrow icon