listview problem

G

Guest

I have a listview (lstvwAmend) (containing 2 columns) that is populated by a filtered dataview (dvRPA) that is based on a dataset (dsRPAmend1) pulling data from a SQL Server database
This dataview will contain 0-10 records.
The dataview is displaying field 1 & field 2 from my dataview
When a user clicks on one of the items in the listview, I want to set the value of a textbox on my form to equal field 3 from the same row in my dataview
I can't seem to make this work

I'm not sure if this is relevant, but pasted below is the code that populates my listbox

lstvwAmend.DataBindings.Clear(
lstvwAmend.Refresh(

DsRPAmend1.Clear(
SqlDA_RPAmend.Fill(DsRPAmend1

dvRPA = New DataVie

With dvRP
.Table = DsRPAmend1.Tables("TDT_ROAD_PERMIT_AMEND"
.RowFilter = "ID_ROAD_PERMIT = '" & txtRPID.Text & "'
.Sort = "NUM_AMENDMENT
End Wit

'create listview to display amendment number and associated C
Dim i As Intege

lstvwAmend.Items.Clear(
lstvwAmend.Refresh(
For i = 0 To dvRPA.Count -
Dim LVI As New ListViewIte
LVI.Text = dvRPA.Item(i).Item(3
If IsDBNull(dvRPA.Item(i).Item(5)) The
Els
LVI.SubItems.Add(dvRPA.Item(i).Item(5)
End I
lstvwAmend.Items.Add(LVI
Nex

Any suggestions
Thanks
amber
 
C

Claes Bergefall

Store each item from dvRPA into the Tag property of the
corresponding ListViewItem, i.e. add this to your loop:
LVI.Tag = dvRPA.Item(i)

Then add a handler to the SelectedIndexChanged event
from the listview and extract the data that you want

/claes

amber said:
I have a listview (lstvwAmend) (containing 2 columns) that is populated by
a filtered dataview (dvRPA) that is based on a dataset (dsRPAmend1) pulling
data from a SQL Server database.
This dataview will contain 0-10 records.
The dataview is displaying field 1 & field 2 from my dataview.
When a user clicks on one of the items in the listview, I want to set the
value of a textbox on my form to equal field 3 from the same row in my
dataview.
 
G

Guest

Thanks for your help
I'm still doing something wrong
I have added the line
LVI.Tag = dvRPA.Item(i
and left the LVI.Text = dvRPA.Item(i) or else the text wouldn't display
So it all looks good, but the textbox still won't update
My code for the SelectedIndexChanged event is
Me.txtAmend.DataBindings.Clear(
Me.txtAmend.DataBindings.Add("text", dvRPA, "ID_ROAD_PERMIT_AMEND"
my dataview (dvRPA) is declared at the class level

I do this exact same thing with my listboxes, with the exact same code, and it works great, but with my listview,
when the listview item is selected, no matter how many items there are, or which one is selected,
the textbox (txtAmend) is always populated with the item that is associated with the first item in the listview

Any ideas

Thanks
Amber
 
C

Claes Bergefall

Do you have to use databinding?

Private Sub OnSelectedIndexChanged()
If myListView.SelectedItems.Count = 0 Then
txtAmend.Text = String.Empty
Else
Dim o as myDataType = CType(myListView.SelectedItems(0).Tag,
myDataType)
txtAmend.Text = o.Item(3).ToString
End If
End Sub

/claes


amber said:
Thanks for your help.
I'm still doing something wrong.
I have added the line:
LVI.Tag = dvRPA.Item(i)
and left the LVI.Text = dvRPA.Item(i) or else the text wouldn't display.
So it all looks good, but the textbox still won't update.
My code for the SelectedIndexChanged event is:
Me.txtAmend.DataBindings.Clear()
Me.txtAmend.DataBindings.Add("text", dvRPA, "ID_ROAD_PERMIT_AMEND")
my dataview (dvRPA) is declared at the class level.

I do this exact same thing with my listboxes, with the exact same code,
and it works great, but with my listview,
when the listview item is selected, no matter how many items there are, or which one is selected,
the textbox (txtAmend) is always populated with the item that is
associated with the first item in the listview.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top