Mohammad Imran
Mohammad Imran

Reputation: 37

Datagridview change color based on condition code not working

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

Answers (2)

waka
waka

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

Rahul
Rahul

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

Related Questions