Connecting Tech Pros Worldwide Forums | Help | Site Map

listview problem

amber
Guest
 
Posts: n/a
#1: Nov 20 '05
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

Claes Bergefall
Guest
 
Posts: n/a
#2: Nov 20 '05

re: listview problem


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" <anonymous@discussions.microsoft.com> wrote in message
news:4FD6F5A3-AAD9-4905-B33B-A8FE6245A508@microsoft.com...[color=blue]
> I have a listview (lstvwAmend) (containing 2 columns) that is populated by[/color]
a filtered dataview (dvRPA) that is based on a dataset (dsRPAmend1) pulling
data from a SQL Server database.[color=blue]
> 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[/color]
value of a textbox on my form to equal field 3 from the same row in my
dataview.[color=blue]
> I can't seem to make this work.
>
> I'm not sure if this is relevant, but pasted below is the code that[/color]
populates my listbox:[color=blue]
>
> lstvwAmend.DataBindings.Clear()
> lstvwAmend.Refresh()
>
> DsRPAmend1.Clear()
> SqlDA_RPAmend.Fill(DsRPAmend1)
>
> dvRPA = New DataView
>
> With dvRPA
> .Table = DsRPAmend1.Tables("TDT_ROAD_PERMIT_AMEND")
> .RowFilter = "ID_ROAD_PERMIT = '" & txtRPID.Text & "'"
> .Sort = "NUM_AMENDMENT"
> End With
>
> 'create listview to display amendment number and associated CP
> Dim i As Integer
>
> lstvwAmend.Items.Clear()
> lstvwAmend.Refresh()
> For i = 0 To dvRPA.Count - 1
> Dim LVI As New ListViewItem
> LVI.Text = dvRPA.Item(i).Item(3)
> If IsDBNull(dvRPA.Item(i).Item(5)) Then
> Else
> LVI.SubItems.Add(dvRPA.Item(i).Item(5))
> End If
> lstvwAmend.Items.Add(LVI)
> Next
>
> Any suggestions?
> Thanks,
> amber[/color]


amber
Guest
 
Posts: n/a
#3: Nov 20 '05

re: listview problem


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
Claes Bergefall
Guest
 
Posts: n/a
#4: Nov 20 '05

re: listview problem


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" <anonymous@discussions.microsoft.com> wrote in message
news:9938FFCD-E156-4238-A341-AC49F3F0BB65@microsoft.com...[color=blue]
> 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,[/color]
and it works great, but with my listview,[color=blue]
> when the listview item is selected, no matter how many items there are, or[/color]
which one is selected,[color=blue]
> the textbox (txtAmend) is always populated with the item that is[/color]
associated with the first item in the listview.[color=blue]
>
> Any ideas?
>
> Thanks,
> Amber[/color]


Closed Thread