1
Hello! I need to hide certain lines from DataGridView
containing in the column data
a date less than the current date. I found this code, but do not know how to hide the lines with this comparison, someone can help me?
private void dgvDados_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
this.dgvDados.Columns[0].SortMode = DataGridViewColumnSortMode.Automatic;
DateTime DataViagem = Convert.ToDateTime(dgvDados.Rows[e.RowIndex].Cells["data"].Value.ToString());
DateTime DataAtual = DateTime.Now.Date;
if (DataViagem <= DataAtual)
{
}
}
You missed that part:
if (row.Cells["data"].Value is DateTime d && d < DateTime.Now)
: Only assignment, call, increment, decrement, await, and new Object Expressions can be used as a statement. Also: The name’d' does not exist in the Current context– Marlon Pereira
updated the answer, which version of c# you use?
– vik
Visual Studio C# 2012
– Marlon Pereira
This error occurred on the line
dgvDados.CurrentCell = null;
, error: Operation is not valid because it results in a reentrant call to the Setcurrentcelladdresscore function.– Marlon Pereira