Click here to Skip to main content
15,895,872 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have few datagridview in same form some are having checkbox and combo box columns
i try to get those column data such as checkbox states to boolean array and combobox text to string array but so many error massages is came.. anyone know How do thais..?


My Purpose is those array will write to text file...

What I have tried:

VB.NET
Public Class Form1

    '// I have insert data grid. its first column is check box and second columns is check box
    '// I want to add to array each row 
    '// And i have few data grid in same form

    Dim data() As String = {}

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '// For first row 

        For a As Integer = 0 To 5
            data(a) = DataGridView1.Rows(a).Cells(0).Value.ToString
            TextBox1.AppendText(data(a))
        Next
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        DataGridView1.Rows.Add(10)
    End Sub
End Class
Posted
Updated 21-Aug-16 10:28am
v2

1 solution

CheckState will return Checked, Unchecked, Indeterminate. But you need a Boolean value, so you look for the Checked Property, not the CheckState Property.


VB.NET
    For a = 1 To 5

       Dim bool As Boolean
       'assuming Cells(x) is a CheckBox
       bool = DataGridView1.Rows(a).Cells(0).Checked


       data(a-1) = bool.ToString
    Next

End Sub
 
Share this answer
 
v3
Comments
Member 12278335 21-Aug-16 23:30pm    
".Checked" is not a member error is coming...
[no name] 22-Aug-16 5:55am    
then modify the code and make sure you are referencing a checkBox.
Further you can view this post about DataGridViews;
http://www.vbforums.com/showthread.php?786065-DataGridView-checks-before-adding-to-other-DataGridView

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900