I need to search a known column in my DataGridView and return the row containing a DateTimeobject with the closest matching time (that is less than the desired search time).
I have used linq in the past to search through a DataGridViewlooking for data. But in those cases, I was looking for an exact match, as in:
public DataGridViewRow FindRow(DataGridView dgv, string columnID, object searchID)
{
DataGridViewRow row = dgv.Rows
.Cast<DataGridViewRow>()
.Where(r => r.Cells[columnID].Value.Equals(searchID))
.First();
return row;
}
Now I have an exact DateTimeobject with a column in my DataGridViewcontaining all DateTimeobjects.
DateAdded Data1 Data2
12:34:56.012 x y
12:34:56.345 x y
12:34:56.678 x y
In the above case, if I am searching for a DateTimeobject of “12:34:56.4”, I want to return the second row containing “12:34:56.345”.
I’m still familiarizing myself with linq. Anytone have any thoughts?
Sometimes asking the questions helps you to answer it yourself…
This did the trick.