Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Porting web navigator from VB6 to VS2005 C#

Porting web navigator from VB6 to VS2005 C#

Scheduled Pinned Locked Moved C#
csharphtmldatabasetutorial
3 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cweeks78681
    wrote on last edited by
    #1

    I am porting a VB 6.0 application to C# that automates navigation of multiple web pages within a site and extracts information from some of the pages. One of the pages contains a listbox containing a number of countries. The default value that is set is not the value I need to use. The HTML in the web page looks like this: All Countries and Territories ------ Australia Austria Belgium Brazil Canada China Denmark Finland France Germany Hong Kong Italy Japan Netherlands Norway Portugal Singapore South Korea Spain Sweden Switzerland Taiwan United Kingdom United States In VB6 the selected value is changed this way: ' De-select the first (default) value in the list wb1.All("country").Options(0).Selected = False ' Select the 26th item (zero-based index) in the list wb1.All("country").selectedIndex = 25 wb1 is an HTMLDocument object. I cannot figure out how to access the Options collection or the selectedIndex property with the .NET 2.0 Webbrowser object. Any ideas how I can do this in C#?

    C 1 Reply Last reply
    0
    • C cweeks78681

      I am porting a VB 6.0 application to C# that automates navigation of multiple web pages within a site and extracts information from some of the pages. One of the pages contains a listbox containing a number of countries. The default value that is set is not the value I need to use. The HTML in the web page looks like this: All Countries and Territories ------ Australia Austria Belgium Brazil Canada China Denmark Finland France Germany Hong Kong Italy Japan Netherlands Norway Portugal Singapore South Korea Spain Sweden Switzerland Taiwan United Kingdom United States In VB6 the selected value is changed this way: ' De-select the first (default) value in the list wb1.All("country").Options(0).Selected = False ' Select the 26th item (zero-based index) in the list wb1.All("country").selectedIndex = 25 wb1 is an HTMLDocument object. I cannot figure out how to access the Options collection or the selectedIndex property with the .NET 2.0 Webbrowser object. Any ideas how I can do this in C#?

      C Offline
      C Offline
      cweeks78681
      wrote on last edited by
      #2

      I don't have access to my development system at the moment to try this out. So, I would appreciate some input as to whether or not this might work: IHTMLDocument3 iDoc3 = (IHTMLDocument3)wb1.Document.DomDocument; IHTMLSelectElement eltCountryList = iDoc3.getElementById("countryList"); eltCountryList.selectedIndex = 25; For now, just ignore the absence of error checking for null pointer values. Is this about the right approach? Will I be able to modify the element's 'selectedIndex' property without any kind of initialization or setup code (sometimes it looks like the HTMLDocument contained in the webbrowser control is read-only)? Do I need to iterate through each element in the list using the IHTMLOptionElement interface and set the 'selected' property to false?

      C 1 Reply Last reply
      0
      • C cweeks78681

        I don't have access to my development system at the moment to try this out. So, I would appreciate some input as to whether or not this might work: IHTMLDocument3 iDoc3 = (IHTMLDocument3)wb1.Document.DomDocument; IHTMLSelectElement eltCountryList = iDoc3.getElementById("countryList"); eltCountryList.selectedIndex = 25; For now, just ignore the absence of error checking for null pointer values. Is this about the right approach? Will I be able to modify the element's 'selectedIndex' property without any kind of initialization or setup code (sometimes it looks like the HTMLDocument contained in the webbrowser control is read-only)? Do I need to iterate through each element in the list using the IHTMLOptionElement interface and set the 'selected' property to false?

        C Offline
        C Offline
        cweeks78681
        wrote on last edited by
        #3

        Here's the code that properly selects an element from the listbox: HtmlElement eltCountryList = webBrowser1.Document.GetElementById("countryList"); HtmlElementCollection eltOptions = eltCountryList.GetElementsByTagName("option"); foreach (HtmlElement op in eltOptions) { op.SetAttribute("selected", ""); // de-select all items in the list } eltOptions[25].SetAttribute("selected", "True"); // set "United States" as the selected item

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups