Hello,
I use the the EditorWithMask all the time to create different masks on columns in a Ultragrids dynamically without any problem. However, today I have encountered a mask that just won't work. I am trying to establish a mask that looks like this "5 min. 10 sec." I want the literals to be written to the database. When I go to edit the value the mask works just fine. When I leave the cell the mask goes away and I am just left with 510.
Here is the code that I am using (in the InitializeRow event):
EmbeddableEditorBase editor = null;DefaultEditorOwnerSettings editorSettings = new DefaultEditorOwnerSettings();
editorSettings.MaskInput = "nn mi\\n. nn sec.";editorSettings.MaskDataMode = MaskMode.IncludeLiterals;editorSettings.MaskDisplayMode = MaskMode.IncludeLiterals;editorSettings.Format = "nn mi\\n. nn sec.";editorSettings.DataType = typeof(DateTime);
editor = new EditorWithMask(new DefaultEditorOwner(editorSettings));
e.Row.Cells["Value"].Editor = editor;
ANY HELP would be greatly appreciated!
Thanks,
Kent
Hi Kent,
What's the data type of the column? When the cell is not in edit mode, the Format property applies. What the grid does is takes the Value of the cell and calls the ToString method on it and passes in the format. My guess is that whatever the data type of your column is, it doesn't suppose the Format string you are passing in.
Thank you for your response Mike.
Your response makes sense, but that does not appear to be the case with this cell. It's a string. I have a EditorWithMask setting up with these settings:
MaskInput = "99 mi\\n. 99 sec.";
MaskDataMode = MaskMode.IncludeLiterals
MaskDisplayMode = MaskMode.IncludeBoth
When I enter data in the cell the mask Input is correct. For example if I want 10 min. 30 secs. I just enter 1030. When I leave the cell all I see is 1030. If I apply a Format in the Editor settings of "# mi\\ n. # sec." I still get 1030. Even if I just make it "# mi\\n." I still get 1030. I would expect at least 1030 min. with this format. However, the format in the editor settings does not appear to be the same as the format on String. so I assume there must be a little more translation involved before String.Format is called. because I would not have to use the \\ in front of the n to have this show up as a literal.
If the column data type is string, then no Format you apply will have any effect, because the String data type does not support any formatting in DotNet.
Check out the string.ToString method and you will see there are no overloads that take any parameters (and therefore none that allows you to pass in a format.
It seems to me that you should not be using a format at all, since you want the actual data to store the literals, anway. If that doesn't work, then something is wrong with the MaskDataMode.