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

Changing the text of a GDBG cell

I am trying to modify the displayed value in a cell without changing the the value in the underlying datarow. Basically I want to performs a units conversion (for display purposes) and leave the original value intact. I guessing it is similar to what you do with cell formatting. Using a formula probably will not work for me because the unit types are looked up when the grid is populated. Any ideas on how to approach this? Thanks, Doug

3 Replies

AD Administrator Syncfusion Team July 27, 2004 12:08 PM

You can do it using grid.PrepareViewStyleInfo. If e.ColIndex points to your column, then set e.Style.Text to be the value you want to see in the grid. Or, you can handle grid.Model.gridDataBoundGrid1.QueryCellFormattedText. Here is a little snippet that displays (100 * the value) in the cell instead of teh value. private void gridControl1_QueryCellFormattedText(object sender, GridCellTextEventArgs e) { if(e.Style.CellValueType == typeof(double) && e.Style.Text.Length > 0) { double val = (double)e.Style.CellValue * 100; e.Text = val.ToString() ; e.Handled = true; } }


DL Doug Lind July 27, 2004 12:48 PM

Thanks for the quick reply! I''ve been trying to use PrepareViewStyleInfo and have been able to change the text, but it leaves the row flagged as edited, which seems to affect the grid update. Almost like there is a cacade of events triggered by me updating the text. Here is a snippet of what I have: Private Sub grid_GridPrepareViewStyleInfo(ByVal sender As Object, ByVal e As GridPrepareViewStyleInfoEventArgs) ''Handles gdbgPatterns.PrepareViewStyleInfo Dim grid As GridDataBoundGrid = sender If e.RowIndex > 0 And e.ColIndex > 0 And grid.GridBoundColumns.Count > 0 Then ''get styleinfo for this column Dim gbc As GridBoundColumn = grid.GridBoundColumns(e.ColIndex) If Not gbc.StyleInfo.Tag Is Nothing Then If gbc.StyleInfo.Tag > Config.MeasureType.NONE Then grid(e.RowIndex, e.ColIndex + 1).Text = "123" End If End If End If End Sub I looked at using QueryCellFormattedText but it isn''t available for a GridDataBoundGrid in V 1.6. Am I missing something? Doug >You can do it using grid.PrepareViewStyleInfo. If e.ColIndex points to your column, then set e.Style.Text to be the value you want to see in the grid. > >Or, you can handle grid.Model.gridDataBoundGrid1.QueryCellFormattedText. Here is a little snippet that displays (100 * the value) in the cell instead of teh value. > > >private void gridControl1_QueryCellFormattedText(object sender, GridCellTextEventArgs e) >{ >if(e.Style.CellValueType == typeof(double) && e.Style.Text.Length > 0) >{ >double val = (double)e.Style.CellValue * 100; >e.Text = val.ToString() ; >e.Handled = true; >} >} >


DL Doug Lind July 27, 2004 01:06 PM

UPDATE: I got it to work us PrepareViewStyleInfo by setting e.Style.Text instead. Thanks, Doug >You can do it using grid.PrepareViewStyleInfo. If e.ColIndex points to your column, then set e.Style.Text to be the value you want to see in the grid. > >Or, you can handle grid.Model.gridDataBoundGrid1.QueryCellFormattedText. Here is a little snippet that displays (100 * the value) in the cell instead of teh value. > > >private void gridControl1_QueryCellFormattedText(object sender, GridCellTextEventArgs e) >{ >if(e.Style.CellValueType == typeof(double) && e.Style.Text.Length > 0) >{ >double val = (double)e.Style.CellValue * 100; >e.Text = val.ToString() ; >e.Handled = true; >} >} >

Loader.
Live Chat Icon For mobile
Up arrow icon