Hi all, quick question here regarding a program Im making. What Im trying to do is load the data from a DataTable (dtMeetings) and put it into a DataGridView, where it will show the rows in the DataTable according to descending dates (one of the columns in the DataTable is a date column). The thing is that once its in the DataGridView, I ONLY want the rows with the date equaling Today to show up (example, on March 21st only the rows with the date column equaling the date 3/21/2013 would appear).
I know for absolutely certain that the column itself consists of the DataType Date because its sorting properly (3/1/2013 shows up as earlier than 1/1/2014 and such) as opposed to the DataType being strings, but I cannot for the life of me get the DataGridView to hide the rows where the date column doesnt equal Today. The date column is column #4 (and I am taking the starting with 0 into effect).
Heres what I have right now:
The first time I open the form where this should be occurring, nothing happens (it just shows all of the rows), then if I close that form and try opening it again the program crashes with the warning error Conversion from type 'DataGridViewRow' to type 'Integer' is not valid. appearing on the If/Then line of code.
I also tried running the program with the following code changes, but the same thing as detailed above happens each time:
Or
Im so close to finishing this program (this is the very last thing I need done) so its getting a bit maddening that this one thing has stopped me dead in my tracks. Ive been up and down Google and various VB.NET forums for hours today trying to find the answer, but no such luck so far. Ive tried changing the way I nest the loop (putting the For loop to a Do Until) and the various ways Ive worded things and played around with the orders, but something just isnt clicking with this program. Thank you in advance for your time and help!
I know for absolutely certain that the column itself consists of the DataType Date because its sorting properly (3/1/2013 shows up as earlier than 1/1/2014 and such) as opposed to the DataType being strings, but I cannot for the life of me get the DataGridView to hide the rows where the date column doesnt equal Today. The date column is column #4 (and I am taking the starting with 0 into effect).
Heres what I have right now:
vb.net Code:
For Each row In dgvMeetings.Rows If Date.Compare(Date.Parse(dgvMeetings.Rows(row).Cells(4).ToString()), Date.Parse(Today)) > 0 Then dgvMeetings.Rows(row).Visible = False End If Next
The first time I open the form where this should be occurring, nothing happens (it just shows all of the rows), then if I close that form and try opening it again the program crashes with the warning error Conversion from type 'DataGridViewRow' to type 'Integer' is not valid. appearing on the If/Then line of code.
I also tried running the program with the following code changes, but the same thing as detailed above happens each time:
vb.net Code:
For Each row In dgvMeetings.Rows If Date.Compare(Date.Parse(dgvMeetings.Rows(row).Cells(4).ToString()), Today) > 0 Then dgvMeetings.Rows(row).Visible = False End If Next
Or
vb.net Code:
For Each row In dgvMeetings.Rows If dgvMeetings.Rows(row).Cells(4).Equals(Today) = True Then dgvMeetings.Rows(row).Visible = False End If Next
Im so close to finishing this program (this is the very last thing I need done) so its getting a bit maddening that this one thing has stopped me dead in my tracks. Ive been up and down Google and various VB.NET forums for hours today trying to find the answer, but no such luck so far. Ive tried changing the way I nest the loop (putting the For loop to a Do Until) and the various ways Ive worded things and played around with the orders, but something just isnt clicking with this program. Thank you in advance for your time and help!