NCSO
asked on
LISTVIEW nightmare with VB2005
Experts,
I am in desperate need of your assistance. I have pulled just about all of my hair out trying to get this listview to work. My project goal is to fill the listview from a database and then fill a textbox with the checked value of the listview. Below is my code:
Private Sub TESTING_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim conn2 As New System.Data.SqlClient.SqlC onnection( "Persist Security Info=True;Server=127.0.0.1 ;Database= Reporting; uid=sa;net work=dbmss ocn;passwo rd=******" )
Dim da2 As New System.Data.SqlClient.SqlD ataAdapter ("Select * from tblPeople", conn2)
Dim ds2 As New System.Data.DataSet
Dim cmd As New System.Data.SqlClient.SqlC ommand("SE LECT * from tbldrug where arn='" & OffenseIncidentEdit.Agency ReportNumb er.Text & "' and Incident_ID='" & OffenseIncidentEdit.Incide nt_ID.Text & "' and deleted='0' order by dateentered", conn2)
Try
conn2.Open()
Dim myReader As SqlDataReader = cmd.ExecuteReader()
Do While myReader.Read()
Dim lvi As New ListViewItem(myReader.Item ("Activity ").ToStrin g) ' This works as far as populating the listview
lvi.SubItems.Add(myReader. Item("Type ").ToStrin g()) ' This works as far as populating the listview
lvi.SubItems.Add(myReader. Item("Desc ription"). ToString() ) ' This works as far as populating the listview
lvi.SubItems.Add(myReader. Item("drug _id").ToSt ring()) ' This works as far as populating the listview (I need this value to populate textbox1 when the selected item is clicked)
ListView1.Items.Add(lvi)
Loop
myReader.Close()
Catch ex As Exception
MessageBox.Show(ex.Message )
Finally
End Try
conn2.Close()
End Sub
My goal is to on click, fill textbox1.text with the selected value "DRUG_ID"
Please help
I am in desperate need of your assistance. I have pulled just about all of my hair out trying to get this listview to work. My project goal is to fill the listview from a database and then fill a textbox with the checked value of the listview. Below is my code:
Private Sub TESTING_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim conn2 As New System.Data.SqlClient.SqlC
Dim da2 As New System.Data.SqlClient.SqlD
Dim ds2 As New System.Data.DataSet
Dim cmd As New System.Data.SqlClient.SqlC
Try
conn2.Open()
Dim myReader As SqlDataReader = cmd.ExecuteReader()
Do While myReader.Read()
Dim lvi As New ListViewItem(myReader.Item
lvi.SubItems.Add(myReader.
lvi.SubItems.Add(myReader.
lvi.SubItems.Add(myReader.
ListView1.Items.Add(lvi)
Loop
myReader.Close()
Catch ex As Exception
MessageBox.Show(ex.Message
Finally
End Try
conn2.Close()
End Sub
My goal is to on click, fill textbox1.text with the selected value "DRUG_ID"
Please help
You will probably get better answers if you post this question in the VB.NET area.
Hi, you'll need to handle the "SelectedIndexChanged" event for the ListView control. Do this by selecting the ListView in design view, in the properties pane select the icon which has a lightning bolt graphic, double click the event named SelectedIndexChanged. This should take you into the code editor and should automatically generate the event handling procedure. In the end you should have something like:
Private Sub ListView1_SelectedIndexCha nged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexCha nged
Me.TextBox1.Text = Me.ListView1.FocusedItem.S ubItems(3) .Text
End Sub
The literal value 3 is the column index...
Hope this helps!
Private Sub ListView1_SelectedIndexCha
Me.TextBox1.Text = Me.ListView1.FocusedItem.S
End Sub
The literal value 3 is the column index...
Hope this helps!
ASKER
Zephyr,
When I click the checkbox, nothing happens.
When I click the checkbox, nothing happens.
ASKER
if I put it "on leave" or "item checked" it show the first indexed return and no other
ASKER
it is as if the focused item is always the first return
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I changed the listview to full row select and it now works but I get the following error when I select a different row:
Object reference not set to an instance of an object.
Object reference not set to an instance of an object.
ASKER
THANK YOU VERRRRRY MUCH!
ASKER