I am having a lot of problems with refreshing this grid. I am updating the GridStyleInfo depending on a checkbox. If the checkbox is checked I want to change the style of another column. The problem is that I seem to only be able to accomplish this in the PrepareViewStyleInfo event. I tried to do this in the CheckBoxClick and the CellClick events but with no success. After I got it working in the PrepareViewStyleInfo I found that the grid doesnt update right away (I need to click around before the style is affected).
Here is the code snippet:
private void dataGrid_PrepareViewStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs e)
if ( !this.initialized )
int iIndex = gridModel.NameToColIndex("InheritFromRole");
int cIndex = gridModel.NameToColIndex("UserValue");
// The Correct Row
if ( e.ColIndex == cIndex )
if ( gridModel[e.RowIndex, iIndex].CellValue is bool )
if ( !(bool)gridModel[e.RowIndex, iIndex].CellValue )
// Static the
e.Style.ReadOnly = false;
e.Style.CellType = "TextBox";
e.Style.BackColor = System.Drawing.Color.White;
else if ( (bool)gridModel[e.RowIndex, iIndex].CellValue )
e.Style.CellType = "Static";
e.Style.ReadOnly = true;
e.Style.Font.Strikeout = true;
e.Style.BackColor = System.Drawing.Color.DeepSkyBlue;
ADAdministrator Syncfusion Team March 11, 2005 01:18 PM
You should not be calling grid.BeginUpdate/EndUpdate or Refresh from within PrepareviewStyleInfo.
To set ReadOnly cell properties in a GridDataboundGrid, you cannot use PrepareviewStyleInfo. Instead, you need to use grid.Model.QueryCellInfo which is raised sooner than PrepareViewStyleInfo. See this KB.
ADAdministrator Syncfusion Team March 11, 2005 03:02 PM
That worked great but my problem with the style not going into affect immediately is still there. The reason I through the begin update and end update in there was mainly to try to get the grid to refresh so the value change would be apparent. Any ideas?
ADAdministrator Syncfusion Team March 11, 2005 03:24 PM
You will need to call grid.Refresh or grid.RefreshRange at the point where you know the grid needs to be refreshed. But this point is not in PrepareViewStyleInfo or QueryCellInfo.
It may be in, say the grid.CurrentCellAcceptedChanges event where grid,CurrentCell.RowIndex/ColIndex point to one of the cell''s whose values is changing that then might how you want the othe rcells to look.
ADAdministrator Syncfusion Team March 11, 2005 03:54 PM
Your the man! I have one last question. There is another column on my grid called "Value". It uses a DataColumn''s expression property to test if InheritFromRole is true or not. IF its true then I use the Column "RowValue" to populate that cell otherwise I use "UserValue". Now the problem I am having is that I cant seem to get that portion of the grid to "refresh". It only does so when I sort on a column or a behavior similar to that. I am currently looking through the documentation of the data grid to see if i can find the correct function to call to refresh the data from the data source. Any help would be appreciated (I feel greedy taking so much of it!).
Again thanks, your the best.
ADAdministrator Syncfusion Team March 11, 2005 04:04 PM
The grid just displays what is in teh datasource, so I think you will have to get teh datasource to refresh itself.
You might try calling this.grid.Binder.EndEdit. This will tell the currencymanager for teh datasource to end its edit, but I suspect this will not trigger the chnage you want.
You might try calling DataTable.AcceptChanges for the daattable that is serving as the datasource for the grid. There is also a DataRow.EndEdit and DataRow.AcceptChanges that you could also try calling. But these calls would be on the data source independent of the grid.
ADAdministrator Syncfusion Team March 11, 2005 05:48 PM
Right! Thanks a lot bud. Ill try to get it to update the data source.
ADAdministrator Syncfusion Team March 11, 2005 06:54 PM
The dataGrid.Binder.EndEdit() forces the currency manager to update and thus refreshes the datasource connection. For all those using expressions in their columns this is the way to do it. Thanks again Clay, worked like a charm.