943,840 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 1333
  • VB.NET RSS
Sep 16th, 2008
0

problem with check boxes and listboxes

Expand Post »
Upon checking the corresponding check box, which is either Ladies Shoes, Men Shoes, Sneakers or Sandals, the program needs fill the listbox with the checkbox information. Can't figure the syntax, any help would be greatly appreciated.

VB Syntax (Toggle Plain Text)
  1. Public Class Form1
  2.  
  3. Private Sub chkboxLadiesShoes_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkboxLadiesShoes.CheckedChanged
  4. Dim ladiesShoes As String = "Ladies Shoes"
  5.  
  6. If chkboxLadiesShoes.CheckState = 1 Then
  7. lstDisplay.Text = ladiesShoes
  8. ElseIf chkboxLadiesShoes.CheckState = 2 Then
  9. lstDisplay.Items.Clear()
  10.  
  11. End If
  12. End Sub
  13.  
  14. Private Sub chkboxMenShoes_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkboxMenShoes.CheckedChanged
  15. Dim menShoes As String = "Men Shoes"
  16. If chkboxMenShoes.CheckState = 1 Then
  17. lstDisplay.Text = menShoes
  18. ElseIf chkboxMenShoes.CheckState = 2 Then
  19. lstDisplay.Items.Clear()
  20.  
  21. End If
  22. End Sub
  23. Private Sub chkSneakers_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkboxSneakers.CheckedChanged
  24. Dim sneakers As String = "Sneakers"
  25. If chkboxSneakers.CheckState = 1 Then
  26. lstDisplay.Text = sneakers
  27. ElseIf chkboxSneakers.CheckState = 2 Then
  28. lstDisplay.Items.Clear()
  29.  
  30. End If
  31. End Sub
  32.  
  33. Private Sub chkSandals_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkboxSandals.CheckedChanged
  34. Dim Sandals As String = "Sandals"
  35. If chkboxSandals.CheckState = 1 Then
  36. lstDisplay.Text = Sandals
  37. ElseIf chkboxSandals.CheckState = 2 Then
  38. lstDisplay.Items.Clear()
  39.  
  40. End If
  41. End Sub
  42.  
  43.  
  44. Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
  45. Me.Close()
  46. End Sub
  47. End Class
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
bpacheco1227 is offline Offline
58 posts
since Jul 2007
Sep 17th, 2008
0

Re: problem with check boxes and listboxes

Not clear...you want to add item into list when user checked it?
Reputation Points: 1182
Solved Threads: 392
Posting Sensei
Jx_Man is offline Offline
3,140 posts
since Nov 2007
Sep 17th, 2008
0

Re: problem with check boxes and listboxes

yes
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
bpacheco1227 is offline Offline
58 posts
since Jul 2007
Sep 17th, 2008
0

Re: problem with check boxes and listboxes

so this line is wrong "lstDisplay.Text"
change with
lstDisplay.Items.Add(CurrentItem)
ex: lstDisplay.Items.Add(ladiesShoes)
Reputation Points: 1182
Solved Threads: 392
Posting Sensei
Jx_Man is offline Offline
3,140 posts
since Nov 2007
Sep 17th, 2008
0

Re: problem with check boxes and listboxes

Thanks, that did it, there's only one more thing. When user unchecks each box the list box should clear, which should be lstDisplay.Items.Clear() which of course does not work, could it be my IF statements? Any insight?
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
bpacheco1227 is offline Offline
58 posts
since Jul 2007
Sep 17th, 2008
2

Re: problem with check boxes and listboxes

Actually i didn't agree with your if statement :
If you want to know check box is checked or not then use Checked function :
Try this :
Private Sub chkboxLadiesShoes_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkboxLadiesShoes.CheckedChanged
        Dim ladiesShoes As String = "Ladies Shoes"

        If chkboxLadiesShoes.Checked = True Then
            lstDisplay.Items.Add(ladiesShoes)
        ElseIf chkboxLadiesShoes.Checked = False Then
            lstDisplay.Items.Clear()
        End If
End Sub
Reputation Points: 1182
Solved Threads: 392
Posting Sensei
Jx_Man is offline Offline
3,140 posts
since Nov 2007
Sep 17th, 2008
0

Re: problem with check boxes and listboxes

great, thank you, works perfectly. Just shows how important syntax is. Thanks Again.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
bpacheco1227 is offline Offline
58 posts
since Jul 2007
Sep 17th, 2008
0

Re: problem with check boxes and listboxes

you're welcome
Reputation Points: 1182
Solved Threads: 392
Posting Sensei
Jx_Man is offline Offline
3,140 posts
since Nov 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: String
Next Thread in VB.NET Forum Timeline: Set COLUMN Borders in a datagrid





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC