Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

I face some error on my code can someone help me take a look thanks

$
0
0

Good Day, i am develop a program for datagridview check box clear check box below is my code

can someone help me take a look

datagriview check box 

Dim CheckboxColumn As DataGridViewCheckBoxColumn = New DataGridViewCheckBoxColumn()
        Dim chk As CheckBox = New CheckBox()
        checkBoxColumn.HeaderText = ""
        checkBoxColumn.Width = 30
        checkBoxColumn.Name = "checkBoxColumn"
        DataGridView1.Columns.Insert(0, checkBoxColumn)

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Clear.Click

        For Each row As DataGridViewRow In DataGridView1.Rows
            Dim chk As DataGridViewCheckBoxCell = CType(row.Cells(1), DataGridViewCheckBoxCell)

            If chk.Selected = True Then
                chk.Selected = False
            Else
                chk.Selected = True
            End If
        Next
        DataGridView1.EndEdit()

    End Sub
End Class

i get error message on Button1_Click 

Unable to cast object of type 'System.Windows.Forms.DataGridViewTextBoxCell' to type 'System.Windows.Forms.DataGridViewCheckBoxCell'.



Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>