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

Set Rows to "read only"

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

5 Replies

AD Administrator Syncfusion Team 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 XP 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


AD Administrator Syncfusion Team 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 XP 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


AD Administrator Syncfusion Team 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);
}

Loader.
Live Chat Icon For mobile
Up arrow icon