Click here to Skip to main content
16,020,669 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My problem is that the items I checked in the datagrid do not appear in the listbox when I press the button, rather the items that are not selected in the datagrid appear in the listbox,so they interchanged.

Here is my code: my button just call this function
Can anyone help me please :(
Any help would be appreciated :)

VB
Public Sub TestThis()
        Dim A1 As Integer = dtg1.RowCount - 2
        Dim A As Integer
        With dtg1
            For A = 0 To A1
                If .Item(2, A).Value = 0 Then
                    If .Item(0, A).Value.ToString <> "" Then
                        ListBox1.Items.Add(.Item(0, A).Value.ToString)
                    End If
                End If

            Next
        End With
End Sub
Posted
Updated 16-Apr-10 0:13am
v2

1 solution

Try changing the .item(2,A).value=0 to .item(2,A).value<>0

0 usually means false so you are checking if the item isn't checked
(Assuming .item(2,A) gets the checked state of the datagrid row)

VB
Public Sub TestThis()
        Dim A1 As Integer = dtg1.RowCount - 2
        Dim A As Integer
        With dtg1
            For A = 0 To A1
                If .Item(2, A).Value <> 0 Then
                    If .Item(0, A).Value.ToString <> "" Then
                        ListBox1.Items.Add(.Item(0, A).Value.ToString)
                    End If
                End If

            Next
        End With
End Sub
 
Share this answer
 

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