Hi all, I really need your help on this one. I have a MSSQL db table with two columns-ID and name. Each row in this two columns contains an unique ID and a name.
Now I have a query that imports just a name in the listview (I don't want ID value in listview). I've put all the values from "ID" column in an array.
Now what I want to do is that when listview item is clicked, the program recongnizes listview selected item index and gets a unique ID (I will need this ID to structure another sql query, but this is not the thing now). So program should recognize list view selected item index and pull out a value from an array which has the same row number as that index.
this is my code so far:
Dim listviewindex As New List(Of Integer)
Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
Dim ConnString As String
Dim SQLStr As String
ConnString = "Data Source=xyz;Initial Catalog=xyz;UID=xyz;Pwd=xyz"
SQLStr = "select * from db.dbo.xyz order by NAME asc"
Dim SQLConn As New SqlConnection()
Dim SQLCmd As New SqlCommand()
Dim dr As SqlDataReader
SQLConn.ConnectionString = ConnString
SQLCmd.Connection = SQLConn
SQLCmd.CommandText = SQLStr
dr = SQLCmd.ExecuteReader
Dim x As Integer
x = ListView1.FocusedItem.Index
What's bugging me first that when I click an item in listview, msgbox(x) gives me correct value on first click, but on second it first gives me index value from previous clicked item and only then it gives me current clicked item index. How can I reset this "click" and how can I get the appropriate ID value from an array.
tnx a lot