I''m using the GridDataBoundGrid (126.96.36.199). It tries to write values back to the data source even when the column is marked as read-only.
This causes a cast exception as the values have been turned into strings by custom cell renderers and the original data source stores doubles. How do I prevent the grid from accessing settor properties on the read-only columns?
ADAdministrator Syncfusion Team October 29, 2004 03:15 AM
I am not sure why this is happening??? If the cell is ReadOnly, the grid should not allow the cell to change, and thus, should not have a reason to try to save it.
But here is something to try. Handle the grid.Model.SaveCellInfo event. In your handler, if e.ColIndex points to the ReadOnly column, and e.RowIndex > 0, then set e.Handled = true to see if this prevents the exception.
If this does not handle the problem, if you will post a little sample showing the problem, maybe we can suggest something else.
ADAdministrator Syncfusion Team November 2, 2004 05:32 AM
Thanks for your reply. I tried adding an event handler to grid.Model.SaveCellInfo but it was never called when the column was resized.
My custom renderers override GetFormattedText(), they were taking a value for a long field and formatting it as a text string. Rather than just returning the formatted string I was also setting style.Text which was attempting to set the value in the datastore and causing the problem.
The custom cell renderers are behaving the way I want them to. Except the currently selected cell ignores the cell justification so all my right justified text shoots to the left. Is there any way to prevent this?
Another problem with using GetFormattedText() is when automatically resizing the column width the grid only sees the unformatted values which happen to be slightly narrower e.g. 123456 rather than ($123,456). Is it possible to add on a margin of error?
ADAdministrator Syncfusion Team November 2, 2004 06:46 AM
SaveCellInfo is only called when a cell value changes. Changing the size of a column should not save anything to your datasource, and this woul dbe why SaveCellInfo is not hit.
Your renderer.Draw method override is responsible for drawing any text properly aligned. Are you overridng this method. If so, you will have to handle the aligment appropriately. If not, I am not sure why the alignment is being ignored. If you can post a little sample project showing the problem, maybe we can spot something here.
And your model.CalculatePreferredCellSize method override is responsible for providing the optimal cell size when ResizeToFit is called. So, if you are not overridng CalculatePreferredCellSize, then you should try that to provide teh size you want the cell to be. A cheap implementation might be to call the base class, and then tweak the value for the extra space before returning it.