473,395 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Porting web navigator from VB6 to VS2005 C#

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:

<select name="country" style="" onchange="" multiple id="countryList"
size="7">
<option value="*" selected> All Countries and Territories </option>
<option value="------0">------</option>
<option value="AU"> Australia </option>
<option value="AT"> Austria </option>
<option value="BE"> Belgium </option>
<option value="BR"> Brazil </option>
<option value="CA"> Canada </option>
<option value="CN"> China </option>
<option value="DK"> Denmark </option>
<option value="FI"> Finland </option>
<option value="FR"> France </option>
<option value="DE"> Germany </option>
<option value="HK"> Hong Kong </option>
<option value="IT"> Italy </option>
<option value="JP"> Japan </option>
<option value="NL"> Netherlands </option>
<option value="NO"> Norway </option>
<option value="PT"> Portugal </option>
<option value="SG"> Singapore </option>
<option value="KR"> South Korea </option>
<option value="ES"> Spain </option>
<option value="SE"> Sweden </option>
<option value="CH"> Switzerland </option>
<option value="TW"> Taiwan </option>
<option value="GB"> United Kingdom </option>
<option value="US"> United States </option>
</select>

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#?

May 7 '06 #1
3 2005
V
hi,
I am not sure but you would probably need to first cast to a ComboBox
type before you can access the properties.

Regards,
Vaibhav

May 7 '06 #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 <SELECT> 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 <OPTION> element in the list using the
IHTMLOptionElement interface and set the 'selected' property to false?

May 8 '06 #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

May 9 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Jake | last post by:
Hi all I am trying to read all the navigator object elements 1. Using the navigator.length returns undefined, cant use for loop; 2.Using and array of known elements like var a =...
13
by: ima | last post by:
Where can I find a list of valid names for Navigator.AppName?
4
by: Chris Travers | last post by:
Hi all; A few years ago, I set about porting a PHP application from MySQL to PostgreSQL, after realizing that MySQL wasn't going to be able to handle it. In order to do this, I built a light,...
4
by: James P. | last post by:
Hello there, I have a bound-form using Navigator so that the user can move back and forth to update record in the form. Every time a record was modified and the user clicks the Navigator to...
3
by: -DG- | last post by:
In C++, there is a compelling reason to recreate projects for the VS2005 compiler rather than simply copy and recompile older code (reason being C++/CLI syntax). I'm wondering if there is any...
2
by: -DG- | last post by:
No reply on my previous query, so I'll post this again. I've done a bit more research in the interim. I'm trying to find an easy way to port code from the older VS2003 format to the format used...
5
by: BK-Chicago | last post by:
I am in the midst of porting a massive MFC application from VS6.0 to VS8.0. While i have fixed most of the compile time errors, i do have quite a linker error that i have not been able to resolve....
3
by: Rick | last post by:
VS 2005 The short version: How can I set the enabled state of a button depending on if a strongly-typed datatable has a DeleteCommand? *************************** The long version:
6
by: =?Utf-8?B?RGlwZXNoX1NoYXJtYQ==?= | last post by:
Hi all, I am porting an code written in VC++ to VC.Net to make it manage. But in Managed VC we dont use "const" keyboard at all. but my code is using it very frequently, so is their any...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.