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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了选中或取消选中DataGridViewCheckBoxColumn上的C#datagridview过滤器相关的知识,希望对你有一定的参考价值。

数据集包含一个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;
答案

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

有一个来自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
}

以上是关于选中或取消选中DataGridViewCheckBoxColumn上的C#datagridview过滤器的主要内容,如果未能解决你的问题,请参考以下文章