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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

ReadOnly GridDataBoundGrid

Thread ID:

Created:

Updated:

Platform:

Replies:

37292 Nov 18,2005 11:43 AM Nov 18,2005 05:29 PM Windows Forms 4
loading
Tags: GridControl
Mike N
Asked On November 18, 2005 11:43 AM

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

Administrator [Syncfusion]
Replied On November 18, 2005 11:53 AM

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.

Mike N
Replied On November 18, 2005 01:21 PM

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

Mike N
Replied On November 18, 2005 01:48 PM

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

Administrator [Syncfusion]
Replied On November 18, 2005 05:29 PM

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";
		}
	}
 
}

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;