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

Cell readonly

Using a griddataboundgrid, I would like a cell to be locked and greyed out until another cell on the same row has valid data.

What is the best way to accomplish this?

4 Replies

AD Administrator Syncfusion Team May 12, 2007 01:16 AM UTC

You can do this by handling grid.Model.QueryCellInfo. There, if e.RowIndex and e.ColIndex point to th ecell you want readonly, then test the value of the other cell to see if you need to set e.Style.Readonly = true.


void Model_QueryCellInfo(object sender, Syncfusion.Windows.Forms.Grid.GridQueryCellInfoEventArgs e)
{
if (e.RowIndex > 0 && e.ColIndex > 0)
{
//make Col2 readonly and gray if Col1 has a 3 in it
if (e.ColIndex == this.gridDataBoundGrid1.Binder.NameToColIndex("Col2"))
{
int colIndex = this.gridDataBoundGrid1.Binder.NameToColIndex("Col1");
object o = this.gridDataBoundGrid1[e.RowIndex, colIndex].CellValue;
if (o != null && o.ToString().Length > 0 &&
(int)this.gridDataBoundGrid1[e.RowIndex, colIndex].CellValue == 3)
{
e.Style.TextColor = SystemColors.GrayText;
e.Style.ReadOnly = true;
}
}
}
}


MA Marc May 12, 2007 03:17 AM UTC

Sounds great except I don't know how to get at the event.


MA Marc May 12, 2007 05:45 AM UTC

>Sounds great except I don't know how to get at the event.

I figured out that I need to add the handler manually but what triggers the event?


AD Administrator Syncfusion Team May 12, 2007 08:05 AM UTC

The event is raised anytime the grid needs a cell value for any reason. So, when the grid draws the cell, the event is raised. When you move the mouse over the cell, the event is rasied. Whenever you index the grid (ie, request grid[row, col]), the event is raised. And so on.

Here are some KBs discussing QueryCellInfo.
kb 1

kb 2

kb 3

Loader.
Live Chat Icon For mobile
Up arrow icon