Link to home
Start Free TrialLog in
Avatar of --laser--
--laser--

asked on

listview control

hey all...
i just got visual studio .net enterprise architect edition so im a newbie to it (i have previously used vb6)

i no this may seem like a really silly question but here goes...

how do i do an event when a certain item in a listview control is selected

i know in vb6 i used to use something like this
            If Item.Index = 1 Then Frame1.Visible = True

i just cant seem to get my head around all these new things


thanks in advance --Laser--
Avatar of Arthur_Wood
Arthur_Wood
Flag of United States of America image

the ListBox control in .NET has a SelectedIndex property, which is EXACTLY equivalent to the Item.Index property that you are familiar with from VB 6:

If MyList.SelectedIndex = 1 then Frame1.Visiable = True

However, with .NET items added to a ListBox can be complete Objects, not just strings, so you can also return the SelectedItem (the object that was selected).  the .NET Listbox also allows Multiple selections, so you can have a SelectedIndeces collection, and a SelectedItems collection as well.  This is very powerful stuff, compared to the limited capabilities that were available with vb 6, and it takes a bit to get your head around the power.

AW
Avatar of --laser--
--laser--

ASKER

yeh i agree that vb .NET is a lot more powerful but i still cant seem to get this to work...

If ListView1.selectedindex = 1 Then MsgBox("hi")

listview1.selectedindex is underlined blue and the tooltip thing says 'selectedindex' is not a member of 'system.windows.forms.listview'
ASKER CERTIFIED SOLUTION
Avatar of arif_eqbal
arif_eqbal

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thank you both very much thats exactly what im looking for arif egbal
just one more thing if you dont mind

this is probably just as easy if not easier...

how do i access a control on a form through a module

like in vb6 it was form1.winsocksend.senddata data
for example

how do i do this in vb.net
See that's not quite the way with Object Oriented programming
You see a Module is now like a global class its public functions are accessible to all but the vice versa is not true. It can only access the Forms/Controls which are made available to it.

You can always have a module level variable that holds a reference to a form but that's not advisable as it is against Encapsulation.

In order to do what you want you should Pass the winsocksend Object as an Argument to the function in the module which will call its method SendData