DataGridView checkbox column - value and functionality

后端 未结 11 1735
一向
一向 2020-11-28 12:17

I\'ve added a checkbox column to a DataGridView in my C# form. The function needs to be dynamic - you select a customer and that brings up all of their items that could be s

11条回答
  •  春和景丽
    2020-11-28 12:54

    1. There is no way to do that directly. Once you have your data in the grid, you can loop through the rows and check each box like this:

      foreach (DataGridViewRow row in dataGridView1.Rows)
      {
          row.Cells[CheckBoxColumn1.Name].Value = true;
      }
      
    2. The Click event might look something like this:

      private void button1_Click(object sender, EventArgs e)
      {
          List rows_with_checked_column = new List();
          foreach (DataGridViewRow row in dataGridView1.Rows)
          {
              if (Convert.ToBoolean(row.Cells[CheckBoxColumn1.Name].Value) == true)
              {
                  rows_with_checked_column.Add(row);
              }
          }
          // Do what you want with the check rows
      }
      

提交回复
热议问题