|
-
Sep 28th, 2004, 12:01 AM
#1
Thread Starter
Addicted Member
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.
-
Sep 28th, 2004, 01:42 AM
#2
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?
-
Sep 28th, 2004, 02:01 AM
#3
Thread Starter
Addicted Member
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.
-
Sep 28th, 2004, 02:10 AM
#4
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:
Private Sub ListBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseUp
ListBox2.Enabled = False
End Sub
Private Sub ListBox2_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox2.MouseUp
ListBox1.Enabled = False
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ListBox1.Enabled = True
ListBox2.Enabled = True
End Sub
-
Sep 28th, 2004, 02:13 AM
#5
Hyperactive Member
here try this one.
VB Code:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
ListBox1.Enabled = True
ListBox2.Enabled = True
End Sub
Private Sub ListBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown
If e.Button = MouseButtons.Left Then
ListBox2.Enabled = False
End If
End Sub
Private Sub ListBox2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox2.MouseDown
If e.Button = MouseButtons.Left Then
ListBox1.Enabled = False
End If
End Sub
-
Sep 28th, 2004, 02:18 AM
#6
Thread Starter
Addicted Member
Thanks it works...
But how to make the highlight thing disappear when one items is being choosen and reset...
-
Sep 28th, 2004, 02:21 AM
#7
Hyperactive Member
add this in the button event:
ListBox1.SelectedIndex = -1
ListBox2.SelectedIndex = -1
-
Sep 28th, 2004, 02:26 AM
#8
Thread Starter
Addicted Member
Thanks everyone....
Both methods works well..
-
Sep 28th, 2004, 02:30 AM
#9
Hyperactive Member
cheers us all
-
Sep 28th, 2004, 02:31 AM
#10
Thread Starter
Addicted Member
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...
-
Sep 28th, 2004, 02:38 AM
#11
Hyperactive Member
try this one.
VB Code:
Private Sub Lstb_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged, ListBox2.SelectedIndexChanged
If sender.name = "ListBox1" Then
TextBox1.Text = ListBox1.SelectedItem
Exit Sub
Else
TextBox1.Text = ListBox2.SelectedItem
Exit Sub
End If
End Sub
-
Sep 28th, 2004, 02:44 AM
#12
Thread Starter
Addicted Member
what is your Lstb refer to...
listbox1 or listbox2..
Thanks
-
Sep 28th, 2004, 02:52 AM
#13
Thread Starter
Addicted Member
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
-
Sep 28th, 2004, 02:54 AM
#14
Hyperactive Member
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:
Private Sub ListBox1_SelectedIndexChange(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
and
Private Sub ListBox2_SelectedIndexChange(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox2.SelectedIndexChanged
hope it helps
-
Sep 28th, 2004, 02:58 AM
#15
Hyperactive Member
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.
-
Sep 28th, 2004, 03:06 AM
#16
Thread Starter
Addicted Member
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
-
Sep 28th, 2004, 03:11 AM
#17
Hyperactive Member
this one, hopes got it
VB Code:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
If ListBox1.Enabled Then
TextBox1.Text = ListBox1.SelectedItem
ElseIf ListBox2.Enabled Then
TextBox1.Text = ListBox2.SelectedItem
End If
ListBox1.Enabled = True
ListBox2.Enabled = True
ListBox1.SelectedIndex = -1
ListBox2.SelectedIndex = -1
End Sub
-
Sep 28th, 2004, 03:16 AM
#18
Thread Starter
Addicted Member
you are really great....
no matters how i ask, you could solve it...
Now all the problems are solve...
Thanks fret
-
Sep 28th, 2004, 03:23 AM
#19
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|