数据集包含一个DataGridViewCheckBoxColumn,我想过滤3种可能的视图:show all(复选框选中和未选中)show show only checked and only unchecked
private void listBoxBehandeld_SelectedValueChanged(object sender, EventArgs e)
{
string listBoxValue = "Alle";
listBoxValue = listBoxBehandeld.GetItemText(listBoxBehandeld.SelectedItem);
switch (listBoxValue)
{
case "Alle":
//Show checked and unchecked
break;
case "Ja":
//show checked
break;
case "Nee":
//show unchecked
}
break;
}
dataGridView.DataSource = meldingenBindingSource;
您需要枚举网格中的行以根据您的案例选择进行过滤。
foreach (DataGridViewRow row in dataGridView.Rows)
{
//Get the appropriate cell using index, name or whatever and cast to DataGridViewCheckBoxCell
DataGridViewCheckBoxCell cell = row.Cells[colCheck] as DataGridViewCheckBoxCell;
//Compare to the true value because Value isn't boolean
if (cell.Value == cell.TrueValue)
//The value is true
}