I'm trying to insert/update Data into a DataGridView but ran into a small Problem.
In the DataGridVieware certain cells with a date and a starting time (datetime).
Now what i'm trying to do is when a button is pressed the current date should be searched for, the row selected, then the start Time should be read and with the current time a TimeSpan should be calculated.
Right now i'm just trying to get the row selected to take out the data of the starttime cell.
var Today = DateTime.Now.ToShortDateString();
dataGridView1.SelectedRows.Clear();
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (row.Cells[0].Value.Equals(Today))
{
row.Selected = true;
}
}
But this gives me an error that the Listing is read only...i'm not really sure what i did wrong here?
So i'd appreaciate it if someone could help me with this or give me a tip on how to solve this Problem.
Thanks in advance to everyone. :)
If you try to clear selection in your DataGridView using dataGridView1.SelectedRows.Clear(); you will receive an exception: Operation not supported. Collection is read-only.
To clear selection, you can use ClearSelection method:
dataGridView1.ClearSelection();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With