[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!
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
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 :)
Re: Combobox - Website problem.
can you post the exact code you're using?
Re: Combobox - Website problem.
Quote:
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
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
Re: Combobox - Website problem.