Results 1 to 10 of 10

Thread: [RESOLVED] Combobox dropdown

  1. #1

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

    Resolved [RESOLVED] Combobox dropdown

    Rephrasing Question:

    In simple terms when I open the dropdown box and see a list of words e.g. Car version 1, Car version 2 etc I want to be able to click Car version 5 for example and that will take me to a website and the same for any other link. I dont want to see the website link in the dropdown list. The website is added in the code against the keyword. Thank you.
    Last edited by jokerfool; May 6th, 2013 at 01:23 PM.

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

    Re: Combobox dropdown

    .....
    Last edited by MetalInquisitor; May 5th, 2013 at 12:33 PM. Reason: didn't understand the question

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

    Re: Combobox dropdown

    So that's fill the combobox with website addresses and navigate to anyone that's selected using the webbrowser control. What's the complication?
    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!

  4. #4

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

    Re: Combobox dropdown

    Im new to this and dont know how to add the control to the list. So if I have the word Google in the list and you select it, then it displays Google.

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

    Re: Combobox dropdown

    Try something like this:

    vb.net Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.  
    5.         'Load urls in the combobox
    6.         ComboBox1.Items.Add("http://www.google.com")
    7.         ComboBox1.Items.Add("http://www.vbforums.com")
    8.        
    9.     End Sub
    10.  
    11.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    12.  
    13.         'go to selected combobox url in webbrowser1
    14.         WebBrowser1.Navigate(ComboBox1.SelectedItem)
    15.  
    16.     End Sub
    17. End Class

  6. #6

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

    Re: Combobox dropdown

    So I got this to work, but this isn't what I am looking for. When I access the dropdown list I need to see the word Google, not the website, plus when I select the website addy I need it to load outside the form, not in a browser in the application, can you help me with this please?

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

    Re: Combobox dropdown

    You could create a class which would have a Name and URL properties. In Name you would have "Google" and in URL you would have "http://www.google.com". You create objects of this class, add their respective Name and URL properties and then add them to the ComboBox. The ComboBox's DisplayMember would be Name so that the CB displays the items' Name in the dropdownlist and the ValueMember would be URL.

    When you select an item from the CB and click a button, you could use Process.Start to start Firefox and the CB.SelectedItem's value member to tell it what URL to open.

    There's probably a simpler way but I'm also still learning the basics of VB.NET.

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Combobox dropdown

    you could use a dictionary(of string, string), with the keys being Google, VBForums, etc, + the values being the associated urls:

    Code:
    Public Class Form1
    
        Dim items As New Dictionary(Of String, String)
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            items.Add("Google", "http://www.google.com")
            items.Add("VBForums", "http://www.vbforums.com")
            ComboBox1.Items.AddRange(items.Keys.ToArray)
        End Sub
    
        Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
            Process.Start(items(ComboBox1.Text))
        End Sub
    
    End Class

  9. #9

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

    Re: Combobox dropdown

    Please read first post, changed the question. Thank you.

  10. #10
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Combobox dropdown

    Quote Originally Posted by jokerfool View Post
    Please read first post, changed the question. Thank you.
    paul's code should do what you're seeking to do.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

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