Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
250
Custom Cell Formatting
posted

I want to be able to apply custom formatting for some of the columns in the UltraGrid.

  • I am using UltraDataSource which has some columns of the double type
  • I am assigning this data source to UltraGrid which displays columns automatically

I want some of my double columns to be formatted in a specific way:

  • If the value is round, it should be displayed as is, for example 128.(0) should be displayed as simply 128
  • If the value has a fractional part, it should be displayed as a multiple of 1/32, for example 128.21875 should be displayed as 128.7/32

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:

  • GetColumnValueAtRow
  • Commit
  • See http://support.microsoft.com/default.aspx?scid=kb;en-us;Q318581

But is there a way to do it for the UltraGrid?

Parents
No Data
Reply
  • 2334
    posted

    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.

Children