Automaticaly Clicking a Checkbox on a webbrowser control

  • Thread starter Thread starter ColliersWNC
  • Start date Start date
C

ColliersWNC

I know there is probably a simple solution to this, but I haven't
figured it out yet or seen it else where.

Imagine you had a simple web page that looked like the following:

<html>
<input name="dgSelect:_ctl0:cbSelect" id="dgSelect__ctl0_cbSelect"
type="checkbox" />
</html>

After loading this web page in to a WebBrowser Control on a VB form,
how would you have VB check the box? I know this seems simple and it's
probably so easy that nobody has bothered to ask it before, but I can't
figure it out and haven't seen a solution for it yet so I thought I'd
ask.

kb
 
Sorry I don't think I was being clear enough, I don't have control
over the creation of the page, it's a 3rd party page. I figured out
what I was trying to do though. I was trying to make a function that
will check every checkbox on a page that is loaded into a webbrowser1
control. There was no preexisting attribute "Checked" on the
checkboxes so I didn't think that I could set it directly, but the code
below works.

hopefully this will help someone out.


private sub Check_all_checkboxes()

Dim doc As HtmlDocument
Dim elem As HtmlElement

doc = WebBrowser1.Document
For Each elem In doc.All
If elem.GetAttribute("type") = "checkbox" Then
elem.SetAttribute("CHECKED", "CHECKED")
End If
Next
End Sub
 
Back
Top