-
Mar 18th, 2012, 01:29 PM
#1
Thread Starter
Lively Member
[RESOLVED] Combobox - Website problem.
Hey.
I want my program to copy all the options in a combobox. and paste it into ComboBox2 in my program.
Here is the combobox i want to copy. http://www.itslearning.com/welcome.aspx
After the user has selected an option from the box, and pressed button1, the program should enter the value of combobox1 into the combobox at the website.
I'm ofcorse doing all this using WebBrowser1.
Can someone please give me a code i can use. I'm a noob and need help.
Thanks!
-
Mar 18th, 2012, 02:01 PM
#2
Re: Combobox - Website problem.
try this:
vb Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'fill combobox
If WebBrowser1.ReadyState <> WebBrowserReadyState.Complete Then Return
Dim element As HtmlElement = WebBrowser1.Document.GetElementById("ctl00_ContentPlaceHolder1_LoginSection1_ChooseSite_site_input")
Dim options() As String = element.GetElementsByTagName("option").Cast(Of HtmlElement).Select(Function(el) el.InnerText).ToArray
ComboBox1.Items.AddRange(options)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'open website in wb
WebBrowser1.Navigate("http://www.itslearning.com/welcome.aspx")
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
'select combobox item in webpage
If ComboBox1.SelectedIndex <> -1 Then
Dim element As HtmlElement = WebBrowser1.Document.GetElementById("ctl00_ContentPlaceHolder1_LoginSection1_ChooseSite_site_input")
Dim optionsElement As HtmlElement = element.GetElementsByTagName("option").Cast(Of HtmlElement).First(Function(el) el.InnerText = ComboBox1.Text)
optionsElement.SetAttribute("selected", "selected")
End If
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Mar 19th, 2012, 09:37 AM
#3
Thread Starter
Lively Member
Re: Combobox - Website problem.
Doesn't seem to work... I don't get any error messages, but the combox1 doesn't seem to load the options.
I press combobox1 (When in debug mode) and there only comes a tiny rectangle down with nothing in it... Where's all the options?? Please help
-
Mar 19th, 2012, 10:53 AM
#4
Re: Combobox - Website problem.
can you post the exact code you're using?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Mar 19th, 2012, 11:18 AM
#5
Thread Starter
Lively Member
Re: Combobox - Website problem.
Originally Posted by .paul.
can you post the exact code you're using?
Sure. Here you go. (Note: In my last post i said combobox1. It's actually combobox2)
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dialog1.ShowDialog()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'open website in wb
WebBrowser1.Navigate("http://www.itslearning.com/welcome.aspx")
'fill combobox
If WebBrowser1.ReadyState <> WebBrowserReadyState.Complete Then Return
Dim element As HtmlElement = WebBrowser1.Document.GetElementById("ctl00_ContentPlaceHolder1_LoginSection1_ChooseSite_site_input")
Dim options() As String = element.GetElementsByTagName("option").Cast(Of HtmlElement).Select(Function(el) el.InnerText).ToArray
ComboBox2.Items.AddRange(options)
End Sub
Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
'select combobox item in webpage
If ComboBox2.SelectedIndex <> -1 Then
Dim element As HtmlElement = WebBrowser1.Document.GetElementById("ctl00_ContentPlaceHolder1_LoginSection1_ChooseSite_site_input")
Dim optionsElement As HtmlElement = element.GetElementsByTagName("option").Cast(Of HtmlElement).First(Function(el) el.InnerText = ComboBox2.Text)
optionsElement.SetAttribute("selected", "selected")
End If
End Sub
End Class
-
Mar 19th, 2012, 11:21 AM
#6
Re: Combobox - Website problem.
vb Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dialog1.ShowDialog()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'open website in wb
WebBrowser1.Navigate("http://www.itslearning.com/welcome.aspx")
End Sub
Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
'select combobox item in webpage
If ComboBox2.SelectedIndex <> -1 Then
Dim element As HtmlElement = WebBrowser1.Document.GetElementById("ctl00_ContentPlaceHolder1_LoginSection1_ChooseSite_site_input")
Dim optionsElement As HtmlElement = element.GetElementsByTagName("option").Cast(Of HtmlElement).First(Function(el) el.InnerText = ComboBox2.Text)
optionsElement.SetAttribute("selected", "selected")
End If
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
'fill combobox
If WebBrowser1.ReadyState <> WebBrowserReadyState.Complete Then Return
Dim element As HtmlElement = WebBrowser1.Document.GetElementById("ctl00_ContentPlaceHolder1_LoginSection1_ChooseSite_site_input")
Dim options() As String = element.GetElementsByTagName("option").Cast(Of HtmlElement).Select(Function(el) el.InnerText).ToArray
ComboBox2.Items.AddRange(options)
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Mar 19th, 2012, 11:47 AM
#7
Thread Starter
Lively Member
Re: Combobox - Website problem.
Awesome! Thanks man!
Tags for this Thread
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
|