Hello
I have a grid bound to a dataset, and one of the columns is of type TimeSpan. When editing a cell's value to this column, I type for example "10:30" and the value is rejected -calified as not valid. The MaskInput property is empty, by the way. What could be wrong?
Thanks a lot.
Okay, I just took a look. The grid has no knowledge of what to do with a TimeSpan object, it just defaults to using a text editor. So if you type a string into the column, the grid will try to convert that string into a TimeSpan using the type converter. Apparently, the type converter for TimeSpan does not handle strings. When I try this, I get an exception:
Convert.ChangeType("10:10:10", typeof(TimeSpan));
So there's no way the grid can handle this.
What you would have to do is use a DataFilter and convert the string to a TimeSpan yourself using TimeSpan.Parse.
I already tried with 6 digits and the same error happened.
The database column is of datatype Time (SQL Server 2008), therefore the DataColumn is of System.Timespan datatype.
What can I do?
I'm not sure the grid can deal with a TimeSpan object. I'm surprised it lets you edit at all. Maybe you need to set the Style property on the column? Or perhaps you need to enter more digits. The default output of the ToString method of a TimeSpan inclues 6 digits if I am not mistaken, so you would need to enter "10:30:00".