Click to See Complete Forum and Search --> : urgent! can anybody help me with listview?


jasie24
December 1st, 2004, 03:19 AM
i want something like this:
when i click on a listviewitem to select all rows that have same tag property

the example below, it works, apparently , but when i click again on the selected rows,i t will remain only one selected , always.why?

my example is :
in form_load() event....

ListView1.View = View.Details
ListView1.LabelEdit = False
ListView1.Columns.Add("nr", 50, HorizontalAlignment.Left)
ListView1.Columns.Add("account", 50, HorizontalAlignment.Left)
ListView1.Columns.Add("sum", 100, HorizontalAlignment.Right)
Dim lve As New ListViewItem
'*1
lve = ListView1.Items.Add("1")
lve.SubItems.Add("1000")
lve.SubItems.Add("250")
lve.Tag = 1
'*2
lve = ListView1.Items.Add("1")
lve.SubItems.Add("2000")
lve.SubItems.Add("-250")
lve.Tag = 1
'*3
lve = ListView1.Items.Add("2")
lve.SubItems.Add("1010")
lve.SubItems.Add("150")
lve.Tag = 2
'*4
lve = ListView1.Items.Add("2")
lve.SubItems.Add("2010")
lve.SubItems.Add("-150")
lve.Tag = 2


and in listview1_mouseUp() event

Dim el As ListViewItem
If ListView1.SelectedItems.Count > 0 Then
Dim index As Integer = ListView1.SelectedItems(0).Index
Dim ta As Integer = ListView1.SelectedItems(0).Tag
For Each el In ListView1.Items
If el.Tag = ta Then
el.Selected = True
Else
el.Selected = False
End If
Next
End If

note:the listview1,has multiselect=true,hideselection=false,fullrowselect=true
from the design.

Krzemo
December 1st, 2004, 03:38 AM
Wrong event - it is fired before new item is selected.

Try to use listview1_clicked() event (or selectedindexchanged event in .NET) instead.

Best regards,
Krzemo.

jasie24
December 2nd, 2004, 02:08 AM
yes but,when you use selected property,in event like selectedindexchanged()
it will go over and over again,will give stackoverflow

in click() i tried,and same result.

Krzemo
December 2nd, 2004, 06:34 AM
yes but,when you use selected property,in event like selectedindexchanged()
it will go over and over again,will give stackoverflowThen block it:
Dim bInternal as boolean
....
in selectedindexchanged():
if not bInternal then
bInternal =true
... your code
end if
bInternal =false

... or something else like that


Hope it helps.

jasie24
December 9th, 2004, 09:31 AM
first solution was to put in mouse_up() all the selection thing, but after that
i noticed that when it's already selected and i clic again on the selected items, it will highlight only the focused,even if the selecteditems.count>1 .

(same strange thing was ,with that boolean variable solution), so

i put in mouse_down()
for each event a
selecteditems.clear()

and it was well, but i find another faster way.
to play with the colors, to change the backgroundcolor and the forecolor when is one selected,it's another way to select them, it goes faster ,and works well with the keyboard as well(i change the selection of items with keys)

thanks any way.