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

问题描述 投票:0回答:1

数据集包含一个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;
c# datagrid
1个回答
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
}
© www.soinside.com 2019 - 2024. All rights reserved.