Re: Programmatically selecting an element

From: Charles Law (blank_at_nowhere.com)
Date: 03/24/04


Date: Wed, 24 Mar 2004 09:31:51 -0000

Hi Mark

Try the following, passing in a reference to the document and the element to
be selected.

<code>
Private Sub SelectElement(ByVal doc2 As mshtml.IHTMLDocument2, ByVal el As
mshtml.IHTMLElement)

    Dim el2 As mshtml.IHTMLElement2
    Dim ctlRg As mshtml.IHTMLControlRange

    If TypeOf el Is mshtml.IHTMLControlElement Then
        el2 = DirectCast(doc2.body, mshtml.IHTMLElement2)
        ctlRg = DirectCast(el2.createControlRange(),
mshtml.IHTMLControlRange)
        ctlRg.add(DirectCast(el, mshtml.IHTMLControlElement))
        ctlRg.select()
    End If

End Sub
</code>

HTH

Charles

"The" <Mark@Microsoftnewsgroups.com> wrote in message
news:%23GZJ6aWEEHA.1376@TK2MSFTNGP10.phx.gbl...
> Hi all.
>
> I asked this question some time back but was unsuccessful in getting an
> answer, so perhaps it's not as obvious as I assumed.
>
> In MSHTML edit mode I'd like to be able to select a specific element in
the
> layout. I thought there would be some way via IHTMLElement, but none of
the
> expected operations - such as click() - work. Currently I'm doing a hack
> using TAB messages, but I'm sure there's some standard way of directly
> selecting (that is, so the item has handles etc).
>
> Perhaps it's a standard OLE thing that's not documented in MSHTML
> interfaces.
>
> Any info greatly appreciated.
>
> MarkC
>
>



Relevant Pages

  • Programmatically selecting an element
    ... I asked this question some time back but was unsuccessful in getting an ... In MSHTML edit mode I'd like to be able to select a specific element in the ... selecting. ... Perhaps it's a standard OLE thing that's not documented in MSHTML ...
    (microsoft.public.inetsdk.programming.webbrowser_ctl)
  • Re: Is this a bug in VB?
    ... However, if any editing is done in the box and then I click on some other control on the form, then the 'On Click' event fires for the combo box? ... Private Sub Combo0_AfterUpdate ... MsgBox "After Greater than 2" ... It always executed the AfterUpdate then the Click event; by entering the values and tabbing or selecting the values from the dropdown via the mouse. ...
    (comp.databases.ms-access)
  • Re: DateTimePicker and restricting dates
    ... Users also have the option of selecting Weekly or ... Private mdtPreviousDate As Date ... Private Sub DTPicker1_Change ... Static bBusy As Boolean ...
    (microsoft.public.vb.controls)
  • Re: Select all when control gets focus
    ... for selecting the whole phone number when you click in ... ... Private Sub Phone_Click ... the length in the control is> len... ... an entry due to focus moving to the intended control after the first click, ...
    (microsoft.public.access.formscoding)
  • Re: Show Blank in Combo After Selection for Search
    ... Thanks to other people in this forum I was able to achieve the exact same ... In the 'On Got Focus' event procedure of the combobox in question add this, ... Private Sub Combo10_GotFocus ... >want (rather than selecting from the list by using the down arrow) and enter ...
    (microsoft.public.access.forms)