I want to be able to apply custom formatting for some of the columns in the UltraGrid.
I want some of my double columns to be formatted in a specific way:
I also want this values to be editable and displayed in the same format while editing.
There is a way to achieve this for the standard Microsoft data grid by overriding the following methods of the DataGridTextBoxColumn:
I believe there are 2 ways to approach this.
1. in the InitializeRowLayout event of the grid set the cell editor to an UltraNumericEditor or UltraMaskedEditor. Then set the Format property of that editor control based on the cells value. You will also want to set the InputMask property to control how the data data looks during edit mode.
2. use a DataFilter. A data filter basically allows you to control the format of data when displaying to or extracting it from the grid. There are several examples of implementing data filters in the help files. There are 4 conversion directions that you can intercept in the data filter to control how the data is diplayed or extracted. OwnerToEditor, EditorToOwner, DisplayToEditor and EditorToDisplay. If you choose to go this route I recommend looking at some of the examples that they provide.
Thanks for your reply!
It seems to me (I haven't tried yet) that this will only work when the user is editing the value.
CellUIElement, for example, doesn't have any properties which would allow you to assign a DataFilter to be used when rendering.
Ok, thanks a lot!
The Editor is used to display the value of the cell as well as editing it. So it will work all the time.
Sorry, but the DataFilter property is available as a property of a visual column's editor, for example: DisplayLayout.Bands[0].Columns[1].Editor.DataFilter = myDataFilter;
Therefore, this conversion functionality will only work only for the editor. In cases when the editor is always visible, this will be fine. But if the editor only appears when you edit the cell, the conversion won't work when the cell is just painted, because it's not painted using the functions of corresponding DataEditor, but using the paint inplementation of its UIElement.
So, I think there is no other way, but to use custom painting...
You apply the DataFilter to the UltraGrid. This filter will be called for each stage of every cell. In the Convert method you must check to see if the cell is in a column you care about.