Reputation: 37
Error 1 The best overloaded method match for 'System.DateTime.Parse(string)' has some invalid arguments
2,Error 2 Argument 1: cannot convert from 'object' to 'string'
if (e.ColumnIndex == 6)
{
var mydatetime = DateTime.Parse(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value);
if (mydatetime.Hour > 9 && mydatetime.Minute > 30)
{
e.CellStyle.BackColor = Color.Yellow;
}
}
Upvotes: 0
Views: 48
Reputation: 3417
Either pass a string to DateTime.Parse
DateTime.Parse(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
or use Convert.ToDateTime
, which accepts object
:
Convert.ToDateTime(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value);
Upvotes: 1
Reputation: 77906
You need to convert that argument to Parse()
method to string
and that's what it's complaining about
var mydatetime = DateTime.Parse(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
Upvotes: 1