选中或取消选中DataGridViewCheckBoxColumn上的C#datagridview过滤器

时间:2018-05-15 12:40:28

标签: c# datagrid

数据集包含一个DataGridViewCheckBoxColumn,我想过滤3种可能的视图:show all(复选框已选中和未选中)仅显示已选中且仅取消选中

 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;

1 个答案:

答案 0 :(得分:0)

您需要根据案例选择枚举网格中的行进行过滤。

有一个例子 https://social.msdn.microsoft.com/Forums/windows/en-US/74df79a9-87ad-4cec-8502-3a357015558d/how-to-check-the-datagridviewcheckboxcolumn-if-its-checked-?forum=winforms

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
}