We help IT Professionals succeed at work.
Get Started

Identify checkbox.checked = True in a datagridview

T Hoecherl
T Hoecherl asked
on
136 Views
Last Modified: 2015-12-21
I have a datagridview that uses a SQL query as the data source.  The last column of the datagridview is a checkbox column.  The code to generate the window is this:

        Dim cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand
        cmd.Connection = cn
        cmd.CommandType = CommandType.Text

        cmd.CommandText = "SELECT ORDER_NUMBER, LINE_NUMBER, QUANTITY, '' AS ADD_WINDOW FROM PCT_PROD_BATCHING WHERE STATUS = 0 ORDER BY ORDER_NUMBER, LINE_NUMBER"
        cmd.CommandTimeout = 0

        Dim dataAdapter As SqlDataAdapter = New SqlDataAdapter(cmd.CommandText, cn)
        dataAdapter.SelectCommand.CommandTimeout = 0
        Dim builder As SqlCommandBuilder = New SqlCommandBuilder(dataAdapter)
        Dim table = New DataTable
        table.Locale = System.Globalization.CultureInfo.InvariantCulture
        dataAdapter.SelectCommand.CommandTimeout = 0
        dgvAddWindow.AutoGenerateColumns = False


        dgvAddWindow.Columns.Add(New DataGridViewTextBoxColumn With {.DataPropertyName = "ORDER_NUMBER", .Name = "Order Number"})
        dgvAddWindow.Columns.Add(New DataGridViewTextBoxColumn With {.DataPropertyName = "LINE_NUMBER", .Name = "Line Number"})
        dgvAddWindow.Columns.Add(New DataGridViewTextBoxColumn With {.DataPropertyName = "QUANTITY", .Name = "Quantity"})
        dgvAddWindow.Columns.Add(New DataGridViewCheckBoxColumn With {.DataPropertyName = "ADD_WINDOW", .Name = "Add Window"})

        dataAdapter.Fill(table)
        AddWindowSource.DataSource = table
        dgvAddWindow.DataSource = AddWindowSource

After selecting rows by checking the checkboxes, and then clicking a Process button, I need to do two things:

1.  Count the number of checkboxes that have been checked.
2.  For each checkbox that has been checked, run some other processes.

I know how to run the other processes, but I don't know how to cycle through the rows and see if the DataGridViewCheckBoxColumn is checked.  Thanks for your help.

T
Comment
Watch Question
Software Architect
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE