Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / August 2006

Tip: Looking for answers? Try searching our database.

Listview - get value multiple columns

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Devlon - 28 Aug 2006 13:13 GMT
Hi,

Does anyone know how to get a value of a second column  of a selected item
in Listview.

I've create a listview and added this code

Listview.Items.Clear()
Listview.Columns.Clear()
Listview.View = View.Details

Listview.Columns.Add("ID", 0, HorizontalAlignment.Left)
Listview.Columns.Add("Toppic", 150, HorizontalAlignment.Left)
Listview.Columns.Add("Name", 150, HorizontalAlignment.Left)
Listview.FullRowSelect = True

I can retreive the data from the first column, i've selected...

myString = Listview.SelectedItems.Item(0)

.. but I can't get any data out of the next columns i've selected...

myString2 = Listview.SelectedItems.Item(1)
myString3 = Listview.SelectedItems.Item(2)

... this doesn' work ...

Does anyone have any idea's

Thanx

John
Al Reid - 28 Aug 2006 13:18 GMT
> Hi,
>
[quoted text clipped - 28 lines]
>
> John

Look at the SibItems collection.

myString2 = Listview.SelectedItems.Item(0).SubItems(1).Text

--
Al Reid
John Devlon - 28 Aug 2006 13:58 GMT
Many thanks for your help ...

At first it worked great

When using it like this ..

Private Sub Listview_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Listview.SelectedIndexChanged
   txtName.Text = Listview.SelectedItems.Item(0).SubItems(1).Text
End Sub

Strange problems occure ...

The first time I select something, it works fine.. the data from the
listview go's into the textfield.
When i select something else, I get a ArgumentOutOfRangeException ...

Any idea's?

john
Al Reid - 28 Aug 2006 14:08 GMT
If there are no selected items you will get this error.  Check the SelectedItems.Count Property.

See inline.

> Many thanks for your help ...
>
[quoted text clipped - 4 lines]
> Private Sub Listview_SelectedIndexChanged(ByVal sender As System.Object,
> ByVal e As System.EventArgs) Handles Listview.SelectedIndexChanged
  If Listview.SelectedItems.Coun > 0 Then
>     txtName.Text = Listview.SelectedItems.Item(0).SubItems(1).Text
  Endif
> End Sub
>
[quoted text clipped - 7 lines]
>
> john

--
Al Reid
John Devlon - 28 Aug 2006 15:33 GMT
Hi,

I've tested the application using your code and I found the problem ...

When selecting something else in a Listview, the methode that handles the
SelectedIndexChanged
is triggerd twice....

First, it sets the selectedItems to 0, then to 1, represting the new
selected value ...

Strang, but the problem is solved ..

Many, Many thanx....

> If there are no selected items you will get this error.  Check the
> SelectedItems.Count Property.
Claes Bergefall - 28 Aug 2006 16:12 GMT
> Hi,
>
[quoted text clipped - 8 lines]
>
> Strang, but the problem is solved ..

Not that strange. This is by design. When you select an item in a ListView
it first deselects the previously selected item and this triggers the first
SelectedIndexChanged (were count = 0). Then it selects the item you clicked
on and this triggers the second SelectedIndexChanged (were count = 1). Hence
the check on count is necessary.

  /claes

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.