locked
Coding for combobox on VB 2010 RRS feed

  • Question

  • Hello Sir,

    I am using visual basic express 2010. I have made 2 windows forms. One is to link with the website(browser form) and the other one is having all the details for text boxes and combo boxes which has to be filled automatically on the desired websites. But here I am having the problems with combo box coding as it is not getting accepted automatically by the website combo box. Only text boxes are functioning properly and details are getting filled automatically on the websites.

    Can anybody help me with the codings of combobox so that it can get accepted and filled automatically on the websites link. I don't have to fill those details manually with down arrow keys on the websites.

    Thanks in advance.    

    Sunday, July 27, 2014 2:37 PM

Answers

  • hello 

    how to make auto fill in webbrowser combobox using visual basic express 2010 web form.

    for auto fill textbox code is

    webbrowser1.document.getelementbyid("username").setattribute("Value", "Userid")

    'webbrowser.document.getelementbyid("password").setattribute("Value", "Password")

    and what will be the code of combobox to autofill.

    please request you to solve the problems.

    thanks

    Hi,

    Based on these words above, it seems that you are closer to the solution to your issue.

    But as I shared in my previous reply, that is still confused which way did you want to do, add options to that combobox or select an item for that combobox ?

    And as Cor shared there may be various control which looks like combobox on a website, so I would recommend you share more detailed information with new reply instead of creating new threads.

    Just to share a sample for add item from combobox on website.

    HTML:

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
    </head>
    <body>
        <select id="selTest">
            <option value="1">text1</option>
            <option value="2">text2</option>
            <option value="3">text3</option>
            <option value="4">text4</option>
        </select>
    </body>
    </html>

    Form1:

       Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
            Dim selObj As HtmlElement = WebBrowser1.Document.GetElementById("selTest")
            For Each obj As HtmlElement In selObj.GetElementsByTagName("option")
                ComboBox1.DisplayMember = "Value"
                ComboBox1.ValueMember = "Key"
                ComboBox1.Items.Add(New DictionaryEntry(obj.GetAttribute("value"), obj.InnerText))
            Next
        End Sub

    Result:

    The way to select items for combobox on website:

     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If ComboBox1.SelectedIndex > -1 Then
                Dim selObj As HtmlElement = WebBrowser1.Document.GetElementById("selTest")
                selObj.SetAttribute("value", DirectCast(ComboBox1.SelectedItem, System.Collections.DictionaryEntry).Key)
            End If
    
        End Sub

    Result:

    For adding items to combobox on website:

    HTML:

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
    </head>
    <body>
        <select id="selTest"  >
    
        </select>
    </body>
    </html>

    Form1:

     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            ComboBox1.DisplayMember = "Value"
            ComboBox1.ValueMember = "Key"
            With ComboBox1.Items
                .Add(New DictionaryEntry("1", "test1"))
                .Add(New DictionaryEntry("2", "test2"))
                .Add(New DictionaryEntry("3", "test3"))
                .Add(New DictionaryEntry("4", "test4"))
            End With
            WebBrowser1.Navigate("D:\Demo\Vb\FillItemsToCombobox0729\WebApplication1\HtmlPage1.html")
        End Sub
    
        Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
            Dim selObj As HtmlElement = WebBrowser1.Document.GetElementById("selTest")
            For index = 0 To ComboBox1.Items.Count - 1
                Dim op As HtmlElement = WebBrowser1.Document.CreateElement("option")
                op.InnerText = DirectCast(ComboBox1.Items(index), System.Collections.DictionaryEntry).Value
                op.SetAttribute("value", op.InnerText = DirectCast(ComboBox1.Items(index), System.Collections.DictionaryEntry).Key)
                selObj.AppendChild(op)
            Next
    
        End Sub

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Carl Cai Tuesday, July 29, 2014 8:20 AM
    • Proposed as answer by Cor Ligthert Tuesday, July 29, 2014 8:40 AM
    • Marked as answer by Carl Cai Monday, August 4, 2014 10:00 AM
    Tuesday, July 29, 2014 8:19 AM
  • Hello,

    Between Carl Cai (last reply which has excellent examples) and my reply pointed out by Carl give you the foundation to work out the ComboBox part and the text boxes uses the same method, just against a different element on the web page.

    Never assume an element exists by ID or InnerText. This is a fundamental aspect of testing a web app using a professional testing tool. Of course we are not in this environment but the logic is sound. Take for example the following code. In button1 click event I want to a) click a button on a web page and also set text and resize an imput element. The last test would have a NullReferenceException if we did not check if the element was null.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    • Marked as answer by Carl Cai Monday, August 4, 2014 10:00 AM
    Tuesday, July 29, 2014 1:43 PM

All replies

  • hello

    how to give link coding to webbrowser with combobox item to autofill in website combobox using webbrowser.

    thanks

    • Merged by Carl Cai Tuesday, July 29, 2014 1:32 AM same issue
    Monday, July 28, 2014 4:51 AM
  • Hello Sir,

    I am using visual basic express 2010. I have made 2 windows forms. One is to link with the website(browser form) and the other one is having all the details for text boxes and combo boxes which has to be filled automatically on the desired websites. But here I am having the problems with combo box coding as it is not getting accepted automatically by the website combo box. Only text boxes are functioning properly and details are getting filled automatically on the websites.

    Can anybody help me with the codings of combobox so that it can get accepted and filled automatically on the websites link. I don't have to fill those details manually with down arrow keys on the websites.

    Thanks in advance.    

    Hi,

    It seems that you have posted the other threads with similar issue, to get better supports, I would recommend you post them with reply in the thread you have posted when you got any concern.

    In this case, I assume you want to fill the options of the combobox on that websites based on the combobox of that windows form, right? Or did you mean select the option for the combobox on website same with the one which the combobox of that windows form selected?

    If I misunderstood anything, please feel free to let me know.

    For getting options of the combobox on website, you could check the following thread:

    http://stackoverflow.com/questions/23520065/using-vb-net-how-to-get-all-options-in-a-select-dropdown-webbrowser

    For selecting item for dropdown list with webbrowser, you could refer to the suggestion shared by Kevininstructor in this thread:

    http://social.msdn.microsoft.com/Forums/vstudio/en-US/89b6b9b7-177a-4216-8512-0d9c1e1703eb/select-item-of-webbrowser-dropdown-list?forum=vbgeneral

    In addition, I would recommend you share your current code and specially the html contents of that website which is quite important to solve this issue.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, July 28, 2014 6:34 AM
  • I didn't realize that a website that has a combobox style control would allow an outside source to add entries to its combobox style control.

    Anytime I've seen a combobox style control on a website it was used so somebody browsing the website could choose something.

    You seem to have created two other unanswered threads along the same lines as this one after looking at your threads Kailash Prajapati's threads and having responded to at least one of the previous threads.

    I'm not certain why you keep posting questions along these lines.  Your supposed to use one thread for a question. The question to me seems similar in each thread you started. So instead of continually starting question threads for basically the same question you should be using your original question thread to respond to responses and ask further questions about the issue in.

    Plus this question "how to give link coding to webbrowser with combobox item to autofill in website combobox using webbrowser." doesn't make any sense to me.

    I understand English is probably not your primary language. But just because you may know some english words does not mean you understand how to use english to present an idea in english. All three of your posts about this really do not make any sense to me. So unless you learn how to use english to present an idea that other people that know english can logically understand then perhaps you should try a forum in your own language.

    Otherwise you're just wasting peoples time in my opinion.


    La vida loca


    Monday, July 28, 2014 6:40 AM
  • hello 

    how to make auto fill in webbrowser combobox using visual basic express 2010 web form.

    for auto fill textbox code is

    webbrowser1.document.getelementbyid("username").setattribute("Value", "Userid")

    'webbrowser.document.getelementbyid("password").setattribute("Value", "Password")

    and what will be the code of combobox to autofill.

    please request you to solve the problems.

    thanks

    • Merged by Barry Wang Tuesday, July 29, 2014 1:36 AM Same case
    Monday, July 28, 2014 6:59 AM
  • Hello Sir

    I am sorry to disturb you, and i dont understand what i want to say you.

    thanks for your opinion.

    Monday, July 28, 2014 7:16 AM
  • You cannot fill a combobox on a website using a webbrowser. A HTML combobox is a pre filled box, from which one item can be selected.

    Try to understand :

    1. How is a website combobox made.
    2. What can you do from the clientside.

    Maybe you want to fill a combobox with the url's from website. That is a complete different question. 

    Link to html combobox (in fact Ajax)

    http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/ComboBox/ComboBox.aspx


    Success
    Cor

    Monday, July 28, 2014 7:39 AM
  • hello 

    how to make auto fill in webbrowser combobox using visual basic express 2010 web form.

    for auto fill textbox code is

    webbrowser1.document.getelementbyid("username").setattribute("Value", "Userid")

    'webbrowser.document.getelementbyid("password").setattribute("Value", "Password")

    and what will be the code of combobox to autofill.

    please request you to solve the problems.

    thanks

    Hi,

    Based on these words above, it seems that you are closer to the solution to your issue.

    But as I shared in my previous reply, that is still confused which way did you want to do, add options to that combobox or select an item for that combobox ?

    And as Cor shared there may be various control which looks like combobox on a website, so I would recommend you share more detailed information with new reply instead of creating new threads.

    Just to share a sample for add item from combobox on website.

    HTML:

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
    </head>
    <body>
        <select id="selTest">
            <option value="1">text1</option>
            <option value="2">text2</option>
            <option value="3">text3</option>
            <option value="4">text4</option>
        </select>
    </body>
    </html>

    Form1:

       Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
            Dim selObj As HtmlElement = WebBrowser1.Document.GetElementById("selTest")
            For Each obj As HtmlElement In selObj.GetElementsByTagName("option")
                ComboBox1.DisplayMember = "Value"
                ComboBox1.ValueMember = "Key"
                ComboBox1.Items.Add(New DictionaryEntry(obj.GetAttribute("value"), obj.InnerText))
            Next
        End Sub

    Result:

    The way to select items for combobox on website:

     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If ComboBox1.SelectedIndex > -1 Then
                Dim selObj As HtmlElement = WebBrowser1.Document.GetElementById("selTest")
                selObj.SetAttribute("value", DirectCast(ComboBox1.SelectedItem, System.Collections.DictionaryEntry).Key)
            End If
    
        End Sub

    Result:

    For adding items to combobox on website:

    HTML:

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
    </head>
    <body>
        <select id="selTest"  >
    
        </select>
    </body>
    </html>

    Form1:

     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            ComboBox1.DisplayMember = "Value"
            ComboBox1.ValueMember = "Key"
            With ComboBox1.Items
                .Add(New DictionaryEntry("1", "test1"))
                .Add(New DictionaryEntry("2", "test2"))
                .Add(New DictionaryEntry("3", "test3"))
                .Add(New DictionaryEntry("4", "test4"))
            End With
            WebBrowser1.Navigate("D:\Demo\Vb\FillItemsToCombobox0729\WebApplication1\HtmlPage1.html")
        End Sub
    
        Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
            Dim selObj As HtmlElement = WebBrowser1.Document.GetElementById("selTest")
            For index = 0 To ComboBox1.Items.Count - 1
                Dim op As HtmlElement = WebBrowser1.Document.CreateElement("option")
                op.InnerText = DirectCast(ComboBox1.Items(index), System.Collections.DictionaryEntry).Value
                op.SetAttribute("value", op.InnerText = DirectCast(ComboBox1.Items(index), System.Collections.DictionaryEntry).Key)
                selObj.AppendChild(op)
            Next
    
        End Sub

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Carl Cai Tuesday, July 29, 2014 8:20 AM
    • Proposed as answer by Cor Ligthert Tuesday, July 29, 2014 8:40 AM
    • Marked as answer by Carl Cai Monday, August 4, 2014 10:00 AM
    Tuesday, July 29, 2014 8:19 AM
  • Hello,

    Between Carl Cai (last reply which has excellent examples) and my reply pointed out by Carl give you the foundation to work out the ComboBox part and the text boxes uses the same method, just against a different element on the web page.

    Never assume an element exists by ID or InnerText. This is a fundamental aspect of testing a web app using a professional testing tool. Of course we are not in this environment but the logic is sound. Take for example the following code. In button1 click event I want to a) click a button on a web page and also set text and resize an imput element. The last test would have a NullReferenceException if we did not check if the element was null.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    • Marked as answer by Carl Cai Monday, August 4, 2014 10:00 AM
    Tuesday, July 29, 2014 1:43 PM