473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

listview problem

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
Nov 20 '05 #1
3 2196
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" <an*******@discussions.microsoft.com> wrote in message
news:4F**********************************@microsof t.com...
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 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

Nov 20 '05 #2
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
Nov 20 '05 #3
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" <an*******@discussions.microsoft.com> wrote in message
news:99**********************************@microsof t.com...
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

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Steph. | last post by:
I use a ListView in a form to display Data from an SQL db. My problem is that I can fill the listview in less than a second when I show the form AFTER filling the listview, but I take 35...
15
by: Wiktor Zychla | last post by:
today we've found a critical issue regarding the ListView from Windows.Forms. it was confirmed on several machines with Win2K and XP. here's the problem: create a ListView with about 50000 rows....
0
by: Sérgio Almeida | last post by:
Greetings I have a problem using listview control. Well, I belive that this is not realy a problem, but it's consuming me precious time. Here is the scenario (an example of my problem). I...
3
by: MikeY | last post by:
Hopefully someone can help me on this. I am using C#, making Windows forms. I have created a listView with checkbox's. I have enabled the checkboxes under the properties, and all the data,...
4
by: firefox | last post by:
Hola Foro!, tengo una rutina que permite agregar varios elementos o items de una sola vez en un ListView. Lo que sucede es que en el momento que se añaden los items al ListView se pone todo blanco,...
4
by: Pucca | last post by:
How can I tell a mouse right clicks over a listview item that's in a container panel. I only want to display a popup menu if the user right click the mouse over an item on the Listview. I don't...
3
by: Martin Panggabean | last post by:
Hello All, I've kind a logic problem ... I want to fill the listView control in VB.NET with data in my mySql table using Datareader object component. But It seems that the way of how listView...
12
by: garyusenet | last post by:
I have had no replies to my previous post so perhaps I didn't write it good enough. Please excuse new thread but i wanted to break from the last thread hopefully this thread will be better. ...
4
by: Brian Gaze | last post by:
I have created a ListView control and have bound this to a datasource. Within the ItemTemplate of the ListView I have added another ListViewControl which is databound in the code behind. The idea...
2
by: =?Utf-8?B?UGhpbGlw?= | last post by:
I am attempting to insert a simple record with LinqDataSource from a ListView, however I always get a message saying "....LinqDataSource 'dataSource' has no values to insert. Check that the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.