473,322 Members | 1,614 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,322 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 2190
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.