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
Conditional cell formatting question
posted

I have a grid that is bound to a custom class that implements IBindingList.

One of the columns is readonly and displays a DateTime value.  I would like to format the DateTime value such that if the value is today, it is "hh:mm:ss".  If the date is before today, I would format it "dd/MM/yyyy".

I cannot use the column format as that is not conditional.

I could change the ListObject implementation to return a formatted string, however that breaks the column filtering.  In other words, greater than filtering does a string compare, rather that a date compare.

Is there anyway to apply this kind of conditional formatting, or to override the filtering logic, such as using a custom IComparer for filtering.

Thanks.

Parents
No Data
Reply
  • 1960
    Suggested Answer
    posted

    One way to do this is:

    1) Add an UltraDateTimeEditor "dtEditorDefault" to your form, set MaskInput to your default format "dd/MM/yyy". That's the editor most rows will use.

    2) Add a second UltraDateTimeEditor "dtEditorToday" to your form, set the MaskInput to "hh:mm:ss". That's the editor you'll use for the cells where the value is today.

    3) For the column you want to format, set UseEditorMaskSettings = true and set the EditorControl = dtEditorDefault.

    4) Add this to the InitializeRow event handler:

    private void ultraGrid1_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
    {
     UltraGridCell dateCell = e.Row.Cells["MyColumnName"];
     if (((DateTime)dateCell.Value) >= DateTime.Today)
     {
      dateCell.EditorControl = dtEditorToday;
     }
    }

Children