Question {ComboBox} Search Navigation Option

VSBrowser

Member
Joined
Sep 21, 2010
Messages
8
Programming Experience
Beginner
Hey Guys,
I am in the middle of making an advanced webbrowser and am stuck on one issue. I found a code on the internet which allows me to put images in a combobox via an imagelist. I have 3 Images 1 for google, 1 for Yahoo and 1 for Youtube. I have come up with a basic code but dont know how to set it so that when i have selected lets say yahoo(image) and type in the search textbox and clik search it will navigate to the images "website"
Image 1 is google
image 2 is youtube
image 3 is yahoo

I named the images
[0] Image1
[1] Image2
[2] Image3

Heres the code I have:

Public Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
If "This should be the selected image in the combobox(google)" Then
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate("http://www.google.com/search?hl=en&q=" & TextBox1.Text & "&btnG=Google+Search&meta="}
End If
If "This should be the selected image in the combobox(youtube)" Then
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate("http://www.youtube.com/results?search_query=" & TextBox1.Text & "&search_type=&aq=-1&oq=")
End If
If "This should be the selected image in the combobox(yahoo)" Then
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate("http://au.search.yahoo.com/search?p=" & TextBox1.Text & "&ei=UTF-8&fr=moz35")
End If
End Sub

If you need anymore code of the combobox images please ask

Thanks
 
Last edited:
Heres the combobox code

Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Me.ComboBox2.Items.AddRange(items)
Me.ComboBox2.DropDownStyle = ComboBoxStyle.DropDownList
Me.ComboBox2.DrawMode = DrawMode.OwnerDrawVariable
Me.ComboBox2.ItemHeight = Me.ImageList1.ImageSize.Height
Me.ComboBox2.Width = Me.ImageList1.ImageSize.Width + 23
Me.ComboBox2.MaxDropDownItems = Me.ImageList1.Images.Count
End Sub


Private Sub ComboBox2_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox2.DrawItem

If e.Index <> -1 Then
e.Graphics.DrawImage(Me.ImageList1.Images(e.Index), e.Bounds.Left, e.Bounds.Top)
End If
End Sub



Private Sub ComboBox2_MeasureItem(ByVal sender As Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles ComboBox2.MeasureItem

e.ItemHeight = Me.ImageList1.ImageSize.Height
e.ItemWidth = Me.ImageList1.ImageSize.Width
End Sub
 
Me.ComboBox2.Items.AddRange(items)
So if 'items' is the strings "google" etc:
VB.NET:
Select Case CStr(combo.SelectedItem)
Case "google"
   browser.Navigate(to google)
'etc
End Select
 
Hey I tried that and got this code


Public Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Select Case CStr(ComboBox2.SelectedItem)
Case "0"
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate("http://www.google.com/search?hl=en&q=" & TextBox1.Text & "&btnG=Google+Search&meta=")
End Select
Select Case CStr(ComboBox2.SelectedItem)
Case "2"
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate("http://www.youtube.com/results?search_query=" & TextBox1.Text & "&search_type=&aq=-1&oq=")
End Select
Select Case CStr(ComboBox2.SelectedItem)
Case "1"
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate("http://au.search.yahoo.com/search?p=" & TextBox1.Text & "&ei=UTF-8&fr=moz35")
End Select
End Sub

is it meant to be like that?

and thats the search button
0 2 1 I subsituted for the image names
aswell when i press on the button it doesnt do anything
 
Public Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Select Case CStr(ComboBox2.SelectedItem)
Case "google"
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate("http://www.google.com/search?hl=en&q=" & TextBox1.Text & "&btnG=Google+Search&meta=")

Case "youtube"
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate("http://www.youtube.com/results?search_query=" & TextBox1.Text & "&search_type=&aq=-1&oq=")

Case "yahoo"
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate("http://au.search.yahoo.com/search?p=" & TextBox1.Text & "&ei=UTF-8&fr=moz35")
End Select
End Sub


or is that right?
 
Is it? How can I know? What does CStr(ComboBox2.SelectedItem) equate to anyway? What is 'items' that you add to the combobox?
 
These are all part of the code that tells the combobox to display images ok here ill explain better

[ComboBox2[\/] [TextBox1 ] [@..] <-----Search button

ComboBox2 has three images in it
[0]Image1
[1]Image2
[2]Image3

These are the image names i set to them in an imagelist(ImageList1)
I showed the code for the combobox b4. That makes it display images.
I got the code for the images from How to Display Images in ComboBox - .Net Articles & Samples

Please Help its urgent
 
So what you're saying is that CStr(ComboBox2.SelectedItem) could be "Image1" or "Image2" ?
 
Yes

Just to make sure I'm getting you Image1 and Image2 and Image 3 are all images from the ImageList1 and are only visible as images in combobox2 here is a link to an image ill show you.

This is in debug and the combobox is dropped down in the top right hand corner

Imageshack - completejpg.png
 
Are you still asking a question, or did you solve it? I keep getting nagging messages from you at my forum profile page!?!
 
Yes and I'm sorry for the nagging. I have been stuck on this for a while and as I'm new to Visual Studio I am sure this is one of the most simple Questions in the world but I am not good enough yet.

Please don't be pissed.
 
Again, this is what you need to find out what is: CStr(ComboBox2.SelectedItem)
 
Back
Top