Forums - C# Corner

Forum guidelines

Add entry into datagridview cell based on another cell value

Jun 29 2013 11:52 AM
I'm trying to auto enter todays date in a datagriview cell when a user clicks a value in another cell to "YES"

I'm nearly there but my code below has something stopping it working?

I think it's on this line: 

if (content.ToLower().Trim() == "YES")

Below is my example:

if (e.ColumnIndex != 4 || e.ColumnIndex != 4) return;
object obj = suppliersDataGridView.Rows[e.RowIndex].Cells[4].Value;

if (obj != null && !DBNull.Value.Equals(obj))
{
string content = obj.ToString();
if (content.ToLower().Trim() == "YES")
{
suppliersDataGridView.Rows[e.RowIndex].Cells[7].Value = DateTime.Now.ToString("dd-MM-yyyy");
}
}

Answers (5)

C# Corner Annual Conference 2017

SPONSORED BY

File APIs for .NET
Aspose are the market leader of .NET APIs for file business formats – natively work with DOCX, XLSX, PPT, PDF, MSG, MPP, images formats and many more!