Problem - Listview.selecteditems

dmc1980

Active member
Joined
Feb 7, 2005
Messages
33
Programming Experience
5-10
Hi folks,

Happy new year to you all, hope you have a good one.

Problem im having here is that if i have a listview, with say 3 columns in it and say 4 rows of data and try to select one of them.

example data (excuse my dodgey columns and rows)

Ingredient - Full Bag - Part Bag
Garlic - 6 - 12
Mayo - 5 - 2
Fruit - 2 - 7
Herbs - 6 - 6


When i double click on the listview, i want to pull this information into text boxes for use by the user. I have this all firing ok with the following code

VB.NET:
Private Sub lvIngredients_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lvIngredients.DoubleClick
Dim SelItems As ListView.SelectedListViewItemCollection = Me.lvIngredients.SelectedItems
txtPickedIngredient.Text = SelItems(0).SubItems(0).Text
txtBagsRequired.Text = SelItems(0).SubItems(1).Text
End Sub

the problem im having is if i pick say the mayo row, txtPcikedIngredients.text will be fine with the mayo in it, but the txtBagsRequired.text returns the bottom row, ie 6 instead of 5.

Anyone have any ideas what im doing wrong ??

Thanks in advance

Darren
 
Your code works fine when I try it, I can't see the problem you describe happening.
 
its got me stumped john, ive tried loads of things and it just keeps happening.

I was wondering could it be something to do with how the listview is populated?
 
Are you modifying the icon spacing? I have had the same troubles that you described and I was setting different icon spacings. Setting the icon spacing to a non square region, i.e. 145x135 instead of 140x140 magically solved to problem.

hth
Hannes
 
Back
Top