Solved

listview control

Posted on 2004-10-20
6
948 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--
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

737 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