Solved

listview control

Posted on 2004-10-20
6
944 Views
Last Modified: 2010-04-24
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--
0
Comment
Question by:--laser--
  • 3
  • 2
6 Comments
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 12358483
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
0
 
LVL 4

Author Comment

by:--laser--
ID: 12363894
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'
0
 
LVL 19

Accepted Solution

by:
arif_eqbal earned 50 total points
ID: 12366884
ListView has a selected Items Collection and SelectedIndices collection

your above code will get modifed to

If ListView1.SelectedIndices.Contains(1) Then MsgBox("hi")



0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Author Comment

by:--laser--
ID: 12366904
thank you both very much thats exactly what im looking for arif egbal
0
 
LVL 4

Author Comment

by:--laser--
ID: 12367321
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
0
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 12367783
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

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now