Page 1 of 1

WebBrowser help

Posted: Mon Nov 26, 2012 7:35 am
by skyteam
Hi guys I am having troubles with this I know the reason of the error but I have no Idea how to fix the code here is the problem and code
Code: Select all
  Dim outputhistory As HtmlElement = WebBrowser2.Document.GetElementById("OutputHistory")
        Dim optionList As HtmlElementCollection = outputhistory.GetElementsByTagName("option")
        Dim strIndex As String = outputhistory.GetAttribute("selectedIndex")
        Dim index As Integer = Integer.Parse(strIndex)

        Dim selectedText As String = optionList(index).InnerText
        pxoutput.Text = selectedText
now the problem is if the Outputhistory equals nothing I get an error and form closes

not sure how to fix this problem If you can help thanks please guys no spamming

Thanks Skyteam

Re: WebBrowser help

Posted: Mon Nov 26, 2012 8:13 am
by muttley1968
do you have to use this code or would you not mind switching as when i did a webbrowser had simillar problems so instead i made a listbox and just added items to it on document complete event and then saved it on form close and loaded it on form load

Re: WebBrowser help

Posted: Mon Nov 26, 2012 10:13 am
by skyteam
muttley1968 wrote:
do you have to use this code or would you not mind switching as when i did a webbrowser had simillar problems so instead i made a listbox and just added items to it on document complete event and then saved it on form close and loaded it on form load
Thing is that the site doesn't always have the same selected item