Results 1 to 19 of 19

Thread: VB.NET: Strange ListBox....[Resolved]

  1. #1

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230

    VB.NET: Strange ListBox....[Resolved]

    Does any one have the idea how to make two listbox or textbox...act like radio button..

    Which means When i select the items form listbox1...
    i should not be able to select from listbox2..

    Thanks
    Last edited by toytoy; Sep 28th, 2004 at 03:18 AM.

  2. #2
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: VB.NET: Strange ListBox

    Originally posted by toytoy
    Does any one have the idea how to make two listbox or textbox...act like radio button..

    Which means When i select the items form listbox1...
    i should not be able to select from listbox2..

    Thanks
    will you pls. explain a little bit broad on your problem.

    is this master-detail relationship?
    listbox1 is the master and listbox2 are the details?

  3. #3

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230
    At first both listbox is enabled and can be choose if something is inside..

    But if i choose either of the listbox....the other will automatic be disabled... that means i should not select from both listbox at the same time...

    Then when i click on another button both listbox will be enable again...

    just does not want both to be selected at the same time when only one is being selected first ..

    Thanks
    Last edited by toytoy; Sep 28th, 2004 at 02:10 AM.

  4. #4
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416
    Originally posted by toytoy
    At first both listbox is enabled and can be choose if something is inside..

    But if i choose either of the listbox....the other will automatic be disabled... that means i should not select from both listbox at the same time...

    Then when i click on another button both listbox will be enable again...

    just does not want both to be selected at the same time when only one is being selected first ..

    Thanks
    VB Code:
    1. Private Sub ListBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseUp
    2.         ListBox2.Enabled = False
    3.      End Sub
    4.  
    5.     Private Sub ListBox2_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox2.MouseUp
    6.         ListBox1.Enabled = False
    7.      End Sub
    8.  
    9.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    10.         ListBox1.Enabled = True
    11.         ListBox2.Enabled = True
    12.     End Sub

  5. #5
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472
    here try this one.
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         ListBox1.Enabled = True
    3.         ListBox2.Enabled = True
    4.     End Sub
    5.  
    6.     Private Sub ListBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown
    7.         If e.Button = MouseButtons.Left Then
    8.             ListBox2.Enabled = False
    9.         End If
    10.     End Sub
    11.  
    12.     Private Sub ListBox2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox2.MouseDown
    13.         If e.Button = MouseButtons.Left Then
    14.             ListBox1.Enabled = False
    15.         End If
    16.     End Sub

  6. #6

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230
    Thanks it works...

    But how to make the highlight thing disappear when one items is being choosen and reset...

  7. #7
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472
    add this in the button event:
    ListBox1.SelectedIndex = -1
    ListBox2.SelectedIndex = -1

  8. #8

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230
    Thanks everyone....

    Both methods works well..


  9. #9
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472
    cheers us all

  10. #10

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230
    Another quick problem...

    How to tell the listbox if i select the items form either listbox...

    That means if i select the item in either listbox, the items should be able to appear in TextBox1...

  11. #11
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472
    try this one.
    VB Code:
    1. Private Sub Lstb_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged, ListBox2.SelectedIndexChanged
    2.         If sender.name = "ListBox1" Then
    3.             TextBox1.Text = ListBox1.SelectedItem
    4.             Exit Sub
    5.         Else
    6.             TextBox1.Text = ListBox2.SelectedItem
    7.             Exit Sub
    8.         End If
    9.     End Sub

  12. #12

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230
    what is your Lstb refer to...

    listbox1 or listbox2..

    Thanks

  13. #13

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230
    It can works.....

    but it skip my button...

    That means if i click on the listbox, it will appear in the textbox without having to click the button....

    Thanks

  14. #14
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472
    Originally posted by toytoy
    what is your Lstb refer to...

    listbox1 or listbox2..

    Thanks
    refer to the listbox1 and listbox2 that it is...both of it will trigger but i have a condition their that will trap each of it (sender.name) on what listbox you selected...
    in other way, you can use this...
    VB Code:
    1. Private Sub ListBox1_SelectedIndexChange(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
    2. and
    3. Private Sub ListBox2_SelectedIndexChange(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox2.SelectedIndexChanged

    hope it helps

  15. #15
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472
    Originally posted by toytoy
    It can works.....

    but it skip my button...

    That means if i click on the listbox, it will appear in the textbox without having to click the button....

    Thanks
    what are you trying to achieve? you mean that after the button event then the selected items in the listbox will appear in the textbox, is that? or i am misleading.

  16. #16

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230
    yeah....

    i want the event to occur only after i click on the button...

    For the code that you given, it will automatic appear to the textbox....

    forget to mention it before posting the question...



    Thanks

  17. #17
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472
    this one, hopes got it
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         If ListBox1.Enabled Then
    3.             TextBox1.Text = ListBox1.SelectedItem
    4.         ElseIf ListBox2.Enabled Then
    5.             TextBox1.Text = ListBox2.SelectedItem
    6.         End If
    7.         ListBox1.Enabled = True
    8.         ListBox2.Enabled = True
    9.         ListBox1.SelectedIndex = -1
    10.         ListBox2.SelectedIndex = -1
    11.     End Sub

  18. #18

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230
    you are really great....

    no matters how i ask, you could solve it...

    Now all the problems are solve...

    Thanks fret

  19. #19
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472
    happy coding

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width