How can I filter a DataColumn on a TimeSpan value?

2019-09-04 23:16发布

问题:

Programming in C#.NET. I have a DataTable with a column named Time which is of type System.TimeSpan. When I display the DataTable in a DataGridView I want to filter out all the entries that don't have a time listed. I have tried the following but to no avail. Can you help?

DataView myDataView = new DataView(SomeDataTable);
myDataView.RowFilter += "Time >= 1";  // doesn't work
myDataView.RowFilter += "Time >= #00:00:01#";  // doesn't work
myDataView.RowFilter += "Time <> ''";  // doesn't work
myDataView.RowFilter += "Time <> ''";  // doesn't work

回答1:

I found it...

myDataView.RowFilter = "Convert(Time, System.String) <> ''";