Results 1 to 19 of 19

Thread: Req: Correct procedure for ComboBox DoubleClick

  1. #1

    Thread Starter
    Hyperactive Member jokerfool's Avatar
    Join Date
    Dec 2006
    Location
    Gold Coast, Australia
    Posts
    452

    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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Addicted Member MetalInquisitor's Avatar
    Join Date
    Sep 2012
    Posts
    143

    Re: Req: Correct procedure for ComboBox

    http://www.vbforums.com/showthread.p...bobox-dropdown

    I thought this was resolved already

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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!

  5. #5

    Thread Starter
    Hyperactive Member jokerfool's Avatar
    Join Date
    Dec 2006
    Location
    Gold Coast, Australia
    Posts
    452

    Re: Req: Correct procedure for ComboBox

    Updated first thread, please read.

  6. #6
    Addicted Member MetalInquisitor's Avatar
    Join Date
    Sep 2012
    Posts
    143

    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: ...

  7. #7
    Addicted Member MetalInquisitor's Avatar
    Join Date
    Sep 2012
    Posts
    143

    Re: Req: Correct procedure for ComboBox

    Quote Originally Posted by jokerfool View Post
    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.

  8. #8

    Thread Starter
    Hyperactive Member jokerfool's Avatar
    Join Date
    Dec 2006
    Location
    Gold Coast, Australia
    Posts
    452

    Re: Req: Correct procedure for ComboBox

    Updated first thread, please read.Just reading this

    http://msdn.microsoft.com/en-us/libr...code-snippet-1

  9. #9

    Thread Starter
    Hyperactive Member jokerfool's Avatar
    Join Date
    Dec 2006
    Location
    Gold Coast, Australia
    Posts
    452

    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?

  10. #10
    Addicted Member MetalInquisitor's Avatar
    Join Date
    Sep 2012
    Posts
    143

    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!

  11. #11
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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!

  12. #12

    Thread Starter
    Hyperactive Member jokerfool's Avatar
    Join Date
    Dec 2006
    Location
    Gold Coast, Australia
    Posts
    452

    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

  13. #13
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  14. #14

    Thread Starter
    Hyperactive Member jokerfool's Avatar
    Join Date
    Dec 2006
    Location
    Gold Coast, Australia
    Posts
    452

    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.

  15. #15
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  16. #16

    Thread Starter
    Hyperactive Member jokerfool's Avatar
    Join Date
    Dec 2006
    Location
    Gold Coast, Australia
    Posts
    452

    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?

  17. #17
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  18. #18

    Thread Starter
    Hyperactive Member jokerfool's Avatar
    Join Date
    Dec 2006
    Location
    Gold Coast, Australia
    Posts
    452

    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
    Code:
    Me.TopMost = True
    option. This is why I required the doubleclick option rather than single.

  19. #19
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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
  •  



Click Here to Expand Forum to Full Width