Good morning,
I have some problems while trying to display a datetime value in the grid.
I use a list of items (BindingList<items>) that is bound to the grid. No problem so far, everything works as expected.
The grid displays the datetime value as date, which seems to be the default behavior.I read in one of the posts that the following formatting condition can be used to display date and time:
{date} {time}
So far, so good. When I apply this condition to the column the correct mask is shown in the designer:__.__.____ __:__:__
Unfortunately when I start the application I get the date and time, but without any formatting at all:30032010092344
Could anybody please be so kind and tell me how to accomplish to display the datetime as mentioned?
Any help is kindly appreciated
best regards
Andy
Hi Andy,
I'm a little fuzzy on what the question is. You say you are are getting the correct mask, but then you say you are not getting the correct mask? I assume you mean the mask is not showing up initially? When does it correct itself? In what event are you setting the MaskInput on the column? Ideally, you should be using the InitializeLayout event of the grid for this.
Hi Mike,
good to hear from you ;)
Sorry if I couldn't explain the problem straight, let me try to clarify it a little bit.
I set the MaskInput of the column to {date} {time}in the "UltraGridDesigner".
After that I get the following displayed in the "Visual Studio Designer":__.__.____ __:__:__
This is when I mentioned "I get the right mask displayed" (in "VS Designer")So the mask looks perfect, just what I expected.
The grid was bound to a BindingList<MyItem> using the "UltraGrid Designer" (Object DataSource).
When I start the application a new BindingList<MyItem> is attached as datasource to the grid and the data is loaded as expected. It is only the DateTime column (with the MaskInput) that shows the date without any formatting, just the numbers of day, month, year, hour, minute, second like that:03032010094500I expected it to be:03.03.2010 09:45:00
I also tried the "Format" property in the meantime, but somehow I just do not succeed.
Thanks a lot for looking into this Mike, I really appreciate your help.
I tried this out and it works fine for me. When I use a MaskInput of "{date} {time}", my DateTime column shows the data like this:
12/26/2018 01:45 AM
Are you setting any of the other mask properties on the column, like the MaskDisplayMode, MaskDataModeMode, MaskClipMode, or Format?
Format will override the Mask when the cell is not in edit mode, and MaskDisplayMode determines whether the mask shows the literals and padding when the cell is not in edit mode.
I have checked the properties you mentioned, here is the result:
MaskClipMode = RawMaskDataMode = RawMaskDisplayMode = RawMaskInput = {date} {time}Format = ''
I only played around a little bit with the Format property, but I never used both together (Format/MaskInput)
The object I bind as datasource is defined like that:
public
class MyItemList : BindingList<MyItem>
and the corresponding field in MyItem like that:
DateTime? changedWhen { get; set; }
I used a nullable DateTime for this, and the UltraGridDesigner recognizes it as System.Nullable`1[System.DateTime]which is perfectly ok.
The cells never switch to edit mode, because it is a read only list, that's where I thought the Format property could be a better place to set the format... unfortunately both didn't work for me.
Do you have any ideas where to look at?
Try different setting for MaskDisplayMode and see if that helps. Setting it to IncludeLiterals or IncludeBoth should do it, I think. I was not able to duplicate the problem on my machine by setting all three values to Raw, but my column was not read-only so that's probably the distinction.
setting the MaskDisplayMode to IncludeBoth did the job.Everything is now displayed as expected.
Thank's a lot for your support, I really appreciate it.