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

Refresh of GridDataBoundGrid

Greetings, 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 ) return; int iIndex = gridModel.NameToColIndex("InheritFromRole"); int cIndex = gridModel.NameToColIndex("UserValue"); // The Correct Row if ( e.ColIndex == cIndex ) { // True if ( gridModel[e.RowIndex, iIndex].CellValue is bool ) { if ( !(bool)gridModel[e.RowIndex, iIndex].CellValue ) { this.dataGrid.BeginUpdate(); // Static the e.Style.ReadOnly = false; e.Style.CellType = "TextBox"; e.Style.BackColor = System.Drawing.Color.White; this.dataGrid.EndUpdate(true); } else if ( (bool)gridModel[e.RowIndex, iIndex].CellValue ) { this.dataGrid.BeginUpdate(); // Test e.Style.CellType = "Static"; e.Style.ReadOnly = true; e.Style.Font.Strikeout = true; e.Style.BackColor = System.Drawing.Color.DeepSkyBlue; this.dataGrid.EndUpdate(true); //this.dataGrid.Refresh(); } } } } }

7 Replies

AD Administrator Syncfusion Team March 11, 2005 06:18 PM UTC

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. http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=95&catId=11

AD Administrator Syncfusion Team March 11, 2005 08:02 PM UTC

Thanks! 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?

AD Administrator Syncfusion Team March 11, 2005 08:24 PM UTC

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.

AD Administrator Syncfusion Team March 11, 2005 08:54 PM UTC

Thanks Clay! 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.

AD Administrator Syncfusion Team March 11, 2005 09:04 PM UTC

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.

AD Administrator Syncfusion Team March 11, 2005 10:48 PM UTC

Right! Thanks a lot bud. Ill try to get it to update the data source. Thanks again.

AD Administrator Syncfusion Team March 11, 2005 11:54 PM UTC

Update: 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.

Live Chat Icon For mobile
Up arrow icon