Activating an ListView Item programmatically? 
Author Message
 Activating an ListView Item programmatically?

Hi,

How can I activate an ListView item programmatically through code?
What I want to achieve is to trigger the ItemActivate event by e.g. Item(0).
I couldn't find any e.g. ListView.Items(0).Activate() method or anything
else to do this.
This ought to be a very important method that should be available!
Am I missing something here?
--
Thanks in advance
Ali Eghtebas Sweden



Thu, 06 Oct 2005 07:14:26 GMT  
 Activating an ListView Item programmatically?
Try

Listview1.Items.Item(0).Selected() = True

Charlie

Quote:
> Hi,

> How can I activate an ListView item programmatically through code?
> What I want to achieve is to trigger the ItemActivate event by e.g.
Item(0).
> I couldn't find any e.g. ListView.Items(0).Activate() method or anything
> else to do this.
> This ought to be a very important method that should be available!
> Am I missing something here?
> --
> Thanks in advance
> Ali Eghtebas Sweden



Thu, 06 Oct 2005 10:40:28 GMT  
 Activating an ListView Item programmatically?
Hi Charlie,

Quote:
> Try

> Listview1.Items.Item(0).Selected() = True

> Charlie

I've tried that already or Listview1.Items(0).Selected = True. But it
doesn't actually Activate the item, since ItemActivate event is never fired.
--
Regards
Ali Eghtebas Sweden


Thu, 06 Oct 2005 17:28:08 GMT  
 Activating an ListView Item programmatically?
Sorry, misunderstood your post

As a workaround you could try calling the ItemActivate from the
SelectedIndexChanged which will be triggered from setting the
item(0).selected()=true.  I'm guessing there's a better way, but I'm too new
at .net to know it :)

Charlie

Quote:
> Hi Charlie,

> > Try

> > Listview1.Items.Item(0).Selected() = True

> > Charlie

> I've tried that already or Listview1.Items(0).Selected = True. But it
> doesn't actually Activate the item, since ItemActivate event is never
fired.
> --
> Regards
> Ali Eghtebas Sweden



Thu, 06 Oct 2005 21:47:49 GMT  
 Activating an ListView Item programmatically?
Hi Ali,

Unfortunately, the API for the control doesn't support what you want to do.
The only way I know of accomplishing what you want is to use SendMessage.
I'll flag your request for a feature request.

As you probably know, a ListView is different from a Listbox in that items
can be activated. From the UI, this is usually acheived by double clicking
the item (though you can change this behavior by setting the control's
Activation property). That's why simply selecting the item doesn't do what
you want.

Hope this helps.

Craig, VB Team
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

Quote:

>Subject: Activating an ListView Item programmatically?
>Date: Sun, 20 Apr 2003 01:14:26 +0200
>Lines: 13
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106

>Newsgroups:

microsoft.public.dotnet.framework,microsoft.public.dotnet.general,microsoft.
public.dotnet.languages.vb
Quote:
>NNTP-Posting-Host: as19-6-8.mt.g.bonet.se 194.236.117.158
>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:91679

microsoft.public.dotnet.languages.vb:102766
microsoft.public.dotnet.framework:42474
Quote:
>X-Tomcat-NG: microsoft.public.dotnet.languages.vb

>Hi,

>How can I activate an ListView item programmatically through code?
>What I want to achieve is to trigger the ItemActivate event by e.g.
Item(0).
>I couldn't find any e.g. ListView.Items(0).Activate() method or anything
>else to do this.
>This ought to be a very important method that should be available!
>Am I missing something here?
>--
>Thanks in advance
>Ali Eghtebas Sweden



Sun, 09 Oct 2005 08:48:46 GMT  
 Activating an ListView Item programmatically?

Quote:
> The only way I know of accomplishing what you want is to use SendMessage.

Ok. How can I do this by SendMessage? SendMessage would do for now!
--
Thanks in advance
Ali Eghtebas Sweden


Sun, 09 Oct 2005 16:46:46 GMT  
 Activating an ListView Item programmatically?
ListView1.Items(0).Selected = True
ListView1.Select()

This works.

Hope this helps, and hope this is what you are looking for.



Sun, 09 Oct 2005 21:10:58 GMT  
 Activating an ListView Item programmatically?

Quote:
> ListView1.Items(0).Selected = True
> ListView1.Select()

Hi Jason, sorry to say that this doesn't do what I need, but thanks anyway.
--
Regards
Ali Eghtebas Sweden


Mon, 10 Oct 2005 02:46:31 GMT  
 Activating an ListView Item programmatically?
Hi Ali,

I'm not necessarily recommending this; it's the only way I could think of
to do what you want. To use SendMessage you first need to declare it
somewhere. To do this, I added the following class to my project:

Imports System.Runtime.InteropServices

Public Class WindowsAPI

    <DllImport("User32.dll", CharSet:=CharSet.Auto)> _
    Public Shared Function SendMessage(ByVal hwnd As IntPtr, ByVal msg As
Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    End Function

    Public Const WM_LBUTTONDBLCLK As Integer = &H203
    Public Const WM_LBUTTONUP As Integer = &H202

End Class

Next, you need to send the double click message to the right item on the
ListView. For this I wrote the following method:

    Private Sub DoubleClickItem(ByVal Item As ListViewItem)

        'Set focus and selection
        Item.Selected = True
        Item.ListView.Focus()

        'Get the handle to the ListView
        Dim hwnd As IntPtr = Item.ListView.Handle

        'Get the dimensions and the point in the middle of the item
        Dim x, y As Integer

        Dim bounds As Rectangle = Item.GetBounds(ItemBoundsPortion.ItemOnly)

        x = bounds.Left + (bounds.Width \ 2)
        y = bounds.Top + (bounds.Height \ 2)

        'Put the coordinates in an lParam (high order = y, low order = x)
        Dim lParam As Integer        
        lParam = y * 2 ^ 16 + x

        'Send double click
        WindowsAPI.SendMessage(hwnd, WindowsAPI.WM_LBUTTONDBLCLK, 0, lParam)
        WindowsAPI.SendMessage(hwnd, WindowsAPI.WM_LBUTTONUP, 0, lParam)

    End Sub

If you call this method and send it an item on ListView1 then the event
ListView1_ItemActivate will be fired. This assumes ListView1.Activation is
ItemActivation.Standard (the default).

Craig, VB Team
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

Quote:
>Subject: Re: Activating an ListView Item programmatically?
>Date: Wed, 23 Apr 2003 10:46:46 +0200
>Lines: 8
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106

>Newsgroups: microsoft.public.dotnet.languages.vb
>NNTP-Posting-Host: as19-6-8.mt.g.bonet.se 194.236.117.158
>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:103366
>X-Tomcat-NG: microsoft.public.dotnet.languages.vb

>> The only way I know of accomplishing what you want is to use SendMessage.

>Ok. How can I do this by SendMessage? SendMessage would do for now!
>--
>Thanks in advance
>Ali Eghtebas Sweden



Tue, 11 Oct 2005 06:04:12 GMT  
 Activating an ListView Item programmatically?
Thanks a lot Craig! I really appreciate the help :)
--
Regards
Ali Eghtebas Sweden



Quote:
> Hi Ali,

> I'm not necessarily recommending this; it's the only way I could think of
> to do what you want. To use SendMessage you first need to declare it
> somewhere. To do this, I added the following class to my project:

> Imports System.Runtime.InteropServices

> Public Class WindowsAPI

>     <DllImport("User32.dll", CharSet:=CharSet.Auto)> _
>     Public Shared Function SendMessage(ByVal hwnd As IntPtr, ByVal msg As
> Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
>     End Function

>     Public Const WM_LBUTTONDBLCLK As Integer = &H203
>     Public Const WM_LBUTTONUP As Integer = &H202

> End Class

> Next, you need to send the double click message to the right item on the
> ListView. For this I wrote the following method:

>     Private Sub DoubleClickItem(ByVal Item As ListViewItem)

>         'Set focus and selection
>         Item.Selected = True
>         Item.ListView.Focus()

>         'Get the handle to the ListView
>         Dim hwnd As IntPtr = Item.ListView.Handle

>         'Get the dimensions and the point in the middle of the item
>         Dim x, y As Integer

>         Dim bounds As Rectangle =

Item.GetBounds(ItemBoundsPortion.ItemOnly)

- Show quoted text -

Quote:

>         x = bounds.Left + (bounds.Width \ 2)
>         y = bounds.Top + (bounds.Height \ 2)

>         'Put the coordinates in an lParam (high order = y, low order = x)
>         Dim lParam As Integer
>         lParam = y * 2 ^ 16 + x

>         'Send double click
>         WindowsAPI.SendMessage(hwnd, WindowsAPI.WM_LBUTTONDBLCLK, 0,
lParam)
>         WindowsAPI.SendMessage(hwnd, WindowsAPI.WM_LBUTTONUP, 0, lParam)

>     End Sub

> If you call this method and send it an item on ListView1 then the event
> ListView1_ItemActivate will be fired. This assumes ListView1.Activation is
> ItemActivation.Standard (the default).

> Craig, VB Team
> This posting is provided "AS IS" with no warranties, and confers no
rights.
> --------------------



> >Subject: Re: Activating an ListView Item programmatically?
> >Date: Wed, 23 Apr 2003 10:46:46 +0200
> >Lines: 8
> >X-Priority: 3
> >X-MSMail-Priority: Normal
> >X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
> >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106

> >Newsgroups: microsoft.public.dotnet.languages.vb
> >NNTP-Posting-Host: as19-6-8.mt.g.bonet.se 194.236.117.158
> >Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
> >Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:103366
> >X-Tomcat-NG: microsoft.public.dotnet.languages.vb

> >> The only way I know of accomplishing what you want is to use
SendMessage.

> >Ok. How can I do this by SendMessage? SendMessage would do for now!
> >--
> >Thanks in advance
> >Ali Eghtebas Sweden



Tue, 11 Oct 2005 19:11:03 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Programmatically double-clicking a ListView Item

2. Programmatically delete an item from the Sent items

3. Programmatically delete an item from the Sent Items Folder

4. programmatically selecting a tabstrip item without clicking an item

5. Programmatically activating a Submit Button

6. jump listview to the hilight item (selected item)...

7. Any Way To Stop All ListView Items From Blinking While Adding Items

8. Drag an item of Listview to another position of the same ListView

9. Listview: check if an item in current listview

10. changing the background of a listview item in the listview control

11. Listview Control - moving items from one listview to another

12. Listview - Changing color of listview items

 

 
Powered by phpBB® Forum Software