Infragistics is throwing and catching a System.FormatExpression every time a cell/column has no data in a formatted cell. Here's some code:
column.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Time; column.Format = "hh:mm"; column.MaskInput = "hh:mm"; column.CellDisplayStyle = CellDisplayStyle.FormattedText; column.MaxLength = 5;
The problem is I have 6 columns that are being accessed and throwing exceptions during any event like clickcell or onmouseover. This is slowing down the program.
Is there a way to fix this other than having to set all my values to some default acceptable values?
Hi,
It's hard to say without knowing what exactly is causing the exception. What's the DataType of the column?
I doubt there's much you can do to avoid the exception on your end, other than what you suggested about providing a default value. But the grid should really avoid exceptions whenever possible, and if this is something that we can detect, we should fix this in the grid. Can you post a small sample project demonstrating the exception so we can check it out?
Figured out how to reproduce the issue. Basically the grid System.FormatExceptions all over the place if you feed it empty strings on a Time column type
You can get around this by making column.style = Infragistics.Win.UltraWinGrid.ColumnStyle.Edit, or several others, instead of Infragistics.Win.UltraWinGrid.ColumnStyle.Time;
The problem with doing this is that it makes the mask pointless. Instead of not letting your user enter illegal values, the grid will cry after the user tries to leave the cell after putting in values it doesn't like. Also the user would have to enter a colon instead of that being a literal they don't have to mess with.
The whole point is that I want the user to be able to type 4 numbers for military time in the cell and that is it. The only way i'm finding to do this is to initialize the string to "00:00" and then parse/convert the string over to just military time after the data has been entered since the grid also wants to set the string to
"8/15/2010 03:53 PM"(A datetime that has been parsed ToString)
Is there a simpler way for me to be doing this that I may be missing?
Sorry I missed this the first time around. When you specify a ColumnStyle of 'Time', it is implied that the data type of the column is DateTime, hence the attempts to format the values as dates.
If your data type is string, don't set the column's Style to 'Time', just let it be; you can get the same mask by setting the MaskInput property to "h:mm" This will stop the format exceptions. If you set the MaskDataMode to 'IncludeLiterals', the colon character will be included with the numeric chars, which will make the value parsable.
That doesn't work, see previous post. Setting MaskDataMode to includeliterals still requires the user to write the colon himself.
lanierhall said:That doesn't work, see previous post. Setting MaskDataMode to includeliterals still requires the user to write the colon himself.
I looked into this some more, and this is all working the way it is supposed to. Setting MaskDataMode to 'IncludeLiterals' will cause the time separator to be written back to the cell, which is what you want so that the string can be parsed into a time.
The value you assign to MaskInput is what determines whether the user has to type a literal character (the colon in this case), so if you assign a value like "h:mm", the user will not have to type the colon.
I changed the code in your sample's constructor because there was some confusing code in there and I couldn't determine which grid the values were being set on. If you use the following code, it works the way you want, as far as I understood you:
public Form1(){ InitializeComponent(); DataTable dt1 = new DataTable("Times"); dt1.Columns.Add("Time0", typeof(string)); dt1.Rows.Add( "" ); dt1.Rows.Add( "" ); dt1.Rows.Add( "" );
this.ultraGrid1.DataSource = dt1;
foreach (UltraGridColumn column in ultraGrid1.DisplayLayout.Bands[0].Columns) { // Use one 'h' in the mask for military time input column.MaskInput = "h:mm";
// Use one or two 'H' for military time format, depending on // whether you want to see leading zeroes (i.e., '04:00' as opposed to '4:00) column.Format = "HH:mm";
// Set the MaskDataMode to 'IncludeLiterals' so that the time separator is // written back to the cell when an edit mode session ends column.MaskDataMode = Infragistics.Win.UltraWinMaskedEdit.MaskMode.IncludeLiterals; }}
I also tried parsing the resulting value into a DateTime and also a TimeSpan, and both worked as expected:
void ultraGrid1_AfterExitEditMode(object sender, EventArgs e){ UltraGrid grid = sender as UltraGrid; string text = grid.ActiveCell.Text; DateTime date = DateTime.Parse( text ); TimeSpan timeSpan = TimeSpan.Parse( text );}
There is no reason you can't use the string data type to store times, and this approach will solve your problem if you need to write strings back to the data source.