Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listview Control - Seletion highlighting problem 2

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
I am playing with a listview control, getting filled in a loop with a very simple add statement, ie Listview.Listitems.add .. A(Loop). I have selected IvyList, and have selected having checkboxes. The control fills okay, but when I for example have two listitems, click on item two's checkbox, the listitem one becomes highlighted??.
Anyone know why, and is there a way of not enabling a listview item being highlighted, as all I want is a bunch of items that I can check/uncheck without any other confusing highlighting, or a way to highlight the listitem being checked/unchecked. If only things were logical? Thanks
 
What about the HideSelection property of a listview? Ladyhawk. [idea]
** ASP/VB/Java Programmer **
 
Tried Hide Selection and its still the same, If I knew how to reference the listview line of data that I'm checking/unchecking, then maybe I can highlight the correct line (ie corresponding to the checkbox)
 
You can reference the selected line of data in a listview by using this code:

Listview.SelectedItem
 
if you can reference a line with listview.selecteditem, how do you pull that information out? For example, if you were to use the itemclick, select the whole row, and highlight an entire row, how can you send that rows information to a textbox? Or multiple textboxes?

Basically, I am pulling info from a database, and displaying things like the record number in a listview. How can you click on the item in the listview, and retrieve that record from the record set (so it can be displayed in various text boxes)?
 
Is this what you are looking for

Listview.SelectedItem.SubItems(X)

X refers to the column number

You can pick out the data in each column by changing X to the column number.

Hope this helps
 
Paddyo, that works great, with one exception. The first column is a list item, not a subitem, and there is no list item option. I cant find any documnetation on this; how do I pull out the list item info?
 
Im not sure exactly what you mean but maybe this is what you want.

Itemyouwant = Listview.Selecteditem
 
Try this

Code:
Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem)
MsgBox Item
End Sub

Let me know if this helps
 
Hi,

Try this

If lvwA.SelectedItem.Index > 0 Then
SelItm = lvwA.SelectedItem.Index
txt1.Text = lvwA.ListItems(SelItm)
txt2.Text = lvwA.ListItems(SelItm).SubItems(1)
TagInfo = lvwA.ListItems(SelItm).tag
End If

you can store your record ID or some unique info of the record in the tag, so that it will be easy for you when u are trying to update or delete any particular record from the table.
 
Great! I ended up using Johnwm's solution. It fit easiest into my code. Though it brought up another problem. When the item is clicked, all the information goes where it is supposed to, however, I have the listview set to visible=false once the item is clicked. But, the listview does not hide. What gives? Here is the whole subroutine.

Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem)
'display the appropriate labels and text boxes

ListView1.Visible = False
Label11.Visible = True
Label12.Visible = True
Label13.Visible = True
Label14.Visible = True
Label15.Visible = True
Label16.Visible = True
Label17.Visible = True
Label18.Visible = True
Label19.Visible = True
txtShowRecNum.Visible = True
txtShowVantive.Visible = True
txtShowIssue.Visible = True
txtShowSBCUID.Visible = True
txtShowNCR.Visible = True
txtShowDate.Visible = True
txtShowSystem.Visible = True
txtShowKeywords.Visible = True
txtShowLog.Visible = True
'empty the text boxes of junk
txtShowRecNum = ""
txtShowVantive = ""
txtShowIssue = ""
txtShowSBCUID = ""
txtShowNCR = ""
txtShowDate = ""
txtShowSystem = ""
txtShowKeywords = ""
txtShowLog = ""
'
lblStatus.Caption = "Processing Request..."

'this allows an itemclick in the listview to be sent to the text boxes
'for file handling
txtShowRecNum.Text = Item
txtShowSBCUID.Text = ListView1.SelectedItem.SubItems(1)
txtShowDate.Text = ListView1.SelectedItem.SubItems(2)
txtShowSystem.Text = ListView1.SelectedItem.SubItems(3)
txtShowKeywords.Text = ListView1.SelectedItem.SubItems(4)
txtShowIssue.Text = ListView1.SelectedItem.SubItems(5)
txtShowNCR.Text = ListView1.SelectedItem.SubItems(6)
txtShowVantive.Text = ListView1.SelectedItem.SubItems(7)
txtShowLog.Text = ListView1.SelectedItem.SubItems(8)

End Sub

I apologize for the easy questions, but I can find no documentation on this.
 
Try using this

Code:
 Private Sub ListView1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
ListView1.Visible = False
End Sub

Let me know if this helps, it always helps to feel appreciated, even if you don't think it's worth a star
 
johnwm....it worked! But what I dont understand is why the program did not hide with the initial code. Any ideas?
And BTW, its worth a star.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top