我想隱藏在數據網格的所有行不以driverNo.Text匹配文本,但是當driverNo.Text是空的,我想所有的datagrid中的行出現。我怎麼做到這一點?隱藏所有行不匹配driverNo.Text
private void driverNo_KeyUp(object sender, KeyEventArgs e)
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (row.Cells[1].Value.ToString() == driverNo.Text)
{
}
else if (row.Cells[1].Value.ToString() == null)
{
}
}
}
一個更好的辦法可能是過濾數據源。這是一個綁定的網格嗎?如果綁定到DataView,則可以使用其過濾器屬性。在上面你可以設置行高爲0,但它不會完全消失。例如row.Height = 0 – rheitzman