Only displaying rows in first column (index 0) where cells match a particular date

后端 未结 1 1457
温柔的废话
温柔的废话 2021-01-28 16:27

How would I hide all rows on my dataGridView that do not match the date of \"27/11/2013\". Currently the code below hides all my rows...

private void viewOverdue         


        
1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-28 17:09

    You should parse your DateTime to string and then compare.

    DateTime dt = DateTime.ParseExact(row.Cells[0].Value.ToString(), "MM/dd/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);
    string d = dt.ToString("dd/M/yyyy");
    if (!string.Equals(d, "27/11/2013", StringComparison.OrdinalIgnoreCase)) {
        row.Visible = false;
    }
    else
    {
        row.Visible = true;
    }
    

    Also implement the following namespace:

    using System.Globalization;
    

    0 讨论(0)
提交回复
热议问题