|
-
May 11th, 2013, 09:47 AM
#1
Thread Starter
Hyperactive Member
Req: Correct procedure for ComboBox DoubleClick
From a previous project and having a dropdown list from using the code below to open the selected url, how do I change this by adding the dblclick command?
Code:
Dim items As New Dictionary(Of String, String)
Private Sub Form20_Load(sender As Object, e As EventArgs) Handles MyBase.Load
items.Add("Google", "http://www.google.com")
items.Add("Yahoo)", "http://www.yahoo.com")
ComboBox2.Items.AddRange(items.Keys.ToArray)
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
Process.Start(items(ComboBox2.Text))
End Sub
End Class
This thread has been updated for the future reference of jmcilhinney, thank you.
Last edited by jokerfool; May 11th, 2013 at 09:03 PM.
-
May 11th, 2013, 09:55 AM
#2
Re: Req: Correct procedure for ComboBox
For future reference, how about you explain what it is that you're trying to do instead of expecting us to work it out from code that doesn't actually do it? I assume (although I shouldn't have to) that you want to add URLs to a ComboBox and then open the selected URL in the user's default browser. If so, to add the item your first get the Items collection of the ComboBox and then call its Add method. As for the opening the URL in a browser, just call Process.Start and pass the URL. There's no other arguments required.
-
May 11th, 2013, 04:55 PM
#3
Addicted Member
Re: Req: Correct procedure for ComboBox
-
May 11th, 2013, 06:43 PM
#4
Re: Req: Correct procedure for ComboBox
When someone double clicks on one of the urls it opens in a browser.
Well, it might help if you used a Double Click event to start with!
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 11th, 2013, 07:35 PM
#5
Thread Starter
Hyperactive Member
Re: Req: Correct procedure for ComboBox
Updated first thread, please read.
-
May 11th, 2013, 07:40 PM
#6
Addicted Member
Re: Req: Correct procedure for ComboBox
nevermind, didn't see the first post, duh
Last edited by MetalInquisitor; May 11th, 2013 at 07:43 PM.
Reason: ...
-
May 11th, 2013, 07:47 PM
#7
Addicted Member
Re: Req: Correct procedure for ComboBox
 Originally Posted by jokerfool
From a previous project and having a dropdown list from using the code below to open the selected url, how do I change this by adding the dblclick command?
Code:
Dim items As New Dictionary(Of String, String)
Private Sub Form20_Load(sender As Object, e As EventArgs) Handles MyBase.Load
items.Add("Google", "http://www.google.com")
items.Add("Yahoo)", "http://www.yahoo.com")
ComboBox2.Items.AddRange(items.Keys.ToArray)
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
Process.Start(items(ComboBox2.Text))
End Sub
End Class
This thread has been updated for the future reference of jmcilhinney, thank you.
The Listbox has a DoubleClick event.
-
May 11th, 2013, 07:48 PM
#8
Thread Starter
Hyperactive Member
Re: Req: Correct procedure for ComboBox
-
May 11th, 2013, 07:49 PM
#9
Thread Starter
Hyperactive Member
Re: Req: Correct procedure for ComboBox
What I dont understand is the difference in the code between double and not double. When I choose the url it opens immediately, how is this changed?
-
May 11th, 2013, 07:51 PM
#10
Addicted Member
Re: Req: Correct procedure for ComboBox
How do you make things happen when you click a button? it's the exact same thing with doubleclick and the listbox!
-
May 11th, 2013, 07:54 PM
#11
Re: Req: Correct procedure for ComboBox
You're using the SelectedIndexChanged event which will fire for single, double, triple, whatever clicks as long as they're all on the same item. If you want to have different behaviour between single and double clicks then you have to take all operations out of SelectedIndexChanged and program specifically for the click and double-click events.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 11th, 2013, 08:55 PM
#12
Thread Starter
Hyperactive Member
Re: Req: Correct procedure for ComboBox
Using this, is there something I am doing wrong?
Code:
Private Sub ComboBox2_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox2.DoubleClick
Process.Start(items(ComboBox2.Text))
End Sub
-
May 11th, 2013, 09:20 PM
#13
Re: Req: Correct procedure for ComboBox DoubleClick
Double-clicking doesn't really make sense when using a ComboBox. With a ListBox maybe, but not a ComboBox.
-
May 11th, 2013, 09:24 PM
#14
Thread Starter
Hyperactive Member
Re: Req: Correct procedure for ComboBox DoubleClick
With the combo box I want to add a search to it later, with the listbox I cant do that.
-
May 11th, 2013, 09:47 PM
#15
Re: Req: Correct procedure for ComboBox DoubleClick
Open the code window and select a ComboBox in the drop-down list at the top-left. Now open the drop-down list on the right to see the list of events for that ComboBox. Notice that DoubleClick is not in that list? That's done for a reason: because that event doesn't make sense for that control. Normally you would only handle the SelectedIndexChanged or SelectionChangeCommitted event of a ComboBox. Otherwise, you might add a Button and use the selection in Click event handler of that Button.
-
May 11th, 2013, 09:54 PM
#16
Thread Starter
Hyperactive Member
Re: Req: Correct procedure for ComboBox DoubleClick
So basically you're saying that I cant have a double click event in visual studio in a ComboBox and I can only have a single click?
-
May 11th, 2013, 10:26 PM
#17
Re: Req: Correct procedure for ComboBox DoubleClick
You can handle the DoubleClick event because, while it's hidden from the designer, it still exists. It doesn't make sense to do so though. You can't double-click and item in the drop-down list anyway because the drop-down closes when you click an item. A double-click on the always-visible part of the control is not intuitive and would no doubt violate the Windows UI guidelines. Like I said, if you want to use the selection at a time other than when the selection is made then you should use a Button.
-
May 11th, 2013, 10:38 PM
#18
Thread Starter
Hyperactive Member
Re: Req: Correct procedure for ComboBox DoubleClick
So even though I successfully did this under VB6 now you say it seems pointless under VS, I have a selection 600+ domains to do with tropical fish, the reason I had the double click was so people could scroll through the list and double click the different sites, my form window didn't disappear because I had the option. This is why I required the doubleclick option rather than single.
-
May 12th, 2013, 06:36 PM
#19
Re: Req: Correct procedure for ComboBox DoubleClick
You can handle the DoubleClick event because, while it's hidden from the designer, it still exists.
Actually, turns out you can't. All clicks are interpreted as single.
so people could scroll through the list and double click the different sites
This kind of functionality is available if you set DropDownStyle to Simple (without the double click, obviously). The list will then stay put!
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
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
|