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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Set Rows to "read only"

Thread ID:

Created:

Updated:

Platform:

Replies:

5424 Jul 2,2003 07:39 AM UTC Jul 2,2003 01:52 PM UTC WinForms 5
loading
Tags: GridControl
XP
Asked On July 2, 2003 07:39 AM UTC

Hi guys, I hope this is not a stupid question :) If it is, take a moment and laugh a bit. I have a GridBoundColumn. In this grid there is a checkbox column, indicating a boolean value in the table. Is it posible to set an entire row as read only, based on the value of that boolean variable. Let's say if the boolean value is "true" and the checkbox is checked, I want to set all the cells from that row to "read only". More... can this be done for more rows in the grid? Please help me. XP

Administrator [Syncfusion]
Replied On July 2, 2003 08:39 AM UTC

You can do this dynamically in the grid.Model.QueryCellInfo event. Here are some snippets.
//in form load, subscribe to the event
this.gridDataBoundGrid1.Model.QueryCellInfo += new GridQueryCellInfoEventHandler(grid_QueryCellInfo);

//in handler, set readonly style depending on checkbox
private void grid_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
	if(e.RowIndex > 0 && e.ColIndex > 0 )
	{
		int checkBoxColIndex = this.gridDataBoundGrid1.Binder.NameToColIndex("checkBoxCol");
		if(e.ColIndex != checkBoxColIndex)
		{
			string s = this.gridDataBoundGrid1[e.RowIndex, checkBoxColIndex].Text;
			if(s.Length > 0 )
				e.Style.ReadOnly = bool.Parse(s);
		}
	}
}

XP
Replied On July 2, 2003 09:32 AM UTC

Thanks Clay, thanks very much!!! It works. Essential grid is a thing to buy along with VS.NET. It is amazing. If it's not to much, can I ask you if it is possible do disable the "delete" action for those rows (those that have the boolean value set to "true"). There are some errors when I try to update the DataSet, so an ideal solution would be to disable the "delete" Thanks again very much, XP

Administrator [Syncfusion]
Replied On July 2, 2003 10:24 AM UTC

I think you can handle the RowsDeleting event and cancel it if one of the rows in checked.
private void gridDataBoundGrid1_RowsDeleting(object sender, GridRowRangeEventArgs e)
{
	int checkBoxColIndex = this.gridDataBoundGrid1.Binder.NameToColIndex("checkBoxCol");
	for(int i = e.From; i <= e.To; ++i)
	{
		GridStyleInfo style = this.gridDataBoundGrid1[e.RowIndex, checkBoxColIndex];
		if(style.Text == style.CheckBoxOptions.CheckedValue)
		{
			e.Cancel = true;
			break;
		}
	}
}

XP
Replied On July 2, 2003 11:23 AM UTC

Thanks again. Indeed, the RowsDeleting event fires up when rows are deleted... but only in the main grid. In the child grids (hieratical ones), this event does bot work. Is there any aother solution? XP

Administrator [Syncfusion]
Replied On July 2, 2003 01:52 PM UTC

You would probably be better served waiting for the 2.0 release which simplifies working with hierarchies. If you want to do it now, you have to handle the RowExpanded and RowCollapsing events and dynamically subscribe\unsubscribe to the childlist.ListChanged event. I am not sur ehow easy it will be to cancel this event though.
private void gridDataBoundGrid1_RowExpanded(object sender, GridRowEventArgs e)
{
	GridBoundRecordState state = gridDataBoundGrid1.Binder.GetRecordStateAtRowIndex(e.RowIndex);
	((IBindingList)state.ChildList).ListChanged += new ListChangedEventHandler(list_ListChanged);
}

private void gridDataBoundGrid1_RowCollapsing(object sender, GridRowEventArgs e)
{
	GridBoundRecordState state = gridDataBoundGrid1.Binder.GetRecordStateAtRowIndex(e.RowIndex);
	((IBindingList)state.ChildList).ListChanged -= new ListChangedEventHandler(list_ListChanged);
}

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.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

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

;