Notifications
Clear all

[Closed] Listview ("..SelectionMode").MultiExtended similar selection mode??

I have a listview that i’d like to behave, like a listbox with it’s (…SelectionMode”).MultiExtended

So i’d be able to marque select items in the listview like a regular MultiListBox.
Has anyone ever done this or know of a work around?
I couldn’t find any info for listview only listboxes.

Cheers

6 Replies

i tried to do this once. couldnt do it. in the end the multiextended dotnet listbox ended up being enough for me. what is it that you need from the listview that you can’t get with a listbox? just columns?

the key word is ITEMS… there is no easy way to customize System.Windows.Forms.ListBox item.
but it’s very easy to make functional listbox from listview. http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.multiselect.aspx#Y510

[font=Verdana]@Gravey
Hi Gravey, I found your listbox you posted in a similar thread on listboxes, cool stuff
Though for this script I’d really like to stick with a listview so i can have the properties of my object be displayed. [/font]

  [font=Verdana] @denisT[/font]

[font=Verdana] Hay Denis, I’m not sure I follow (still new to .net), are you saying it’s easy to make a listbox out of a listview? I’d prefer to stick with a listview if possible.[/font]
[font=Verdana] I read the microsoft listview.multiselct property and already have it set to true, but that doesn’t allow the user to marque select Items. Would it be possible to mimic it with mouse events?[/font]

  [font=Verdana] Also If I have multiple items selected in the listview, is there a easy way to get the collection of items?[/font]

[font=Verdana] lv.selecteditems will give me:[/font]
[font=Verdana] dotNetObject:System.Windows.Forms.ListView+SelectedListViewItemCollection[/font]
[font=Verdana] but the properties on that only have item[index][/font]
[font=Verdana] and lv.SelectedIndices has a item[index] aswell[/font]

  [font=Verdana] Do I  have to test each item's selected state in the listview, in order to get an array of all dotNetObjects selected?[/font]

  [font=Verdana] Cheers[/font]

hey Alex ,try this for a start:

i remember Joel’s post, but I used this approach recently to get the functionality I needed –

rollout ListViewRo "" width:169 height:225
(
	local lvBits = #("Weasels","Badgers","Stoats","Shrews","Mice","Ocelots","Guinea Pigs")

	fn setupList lv =
	(
		lv.backcolor = lv.backcolor.gray
		lv.forecolor = lv.forecolor.ghostwhite
		lv.view = lv.view.details
		lv.FullRowSelect=true		--Set so full width of listView is selected and not just first column.
		lv.GridLines=false		--Show lines between the items. 
		lv.MultiSelect=true			--Allow for multiple selections. 		
		lv.checkboxes = true
		lv.fullrowselect = true
		lv.headerstyle = lv.headerstyle.none
		lv.hideselection = false 
		lv.columns.add "Items" 145
	)
		
	fn displayListData lv mca = 
	(
		rows = for x in mca collect	
		(
			li=dotNetObject "System.Windows.Forms.ListViewItem" x	--Create a listViewItem object and name it. 
			li.checked = true
			li --Added the listViewItem to the rows array
		)
		lv.items.addRange rows		
	)
		
	dotNetControl mLv "listview" pos:[6,5] width:157 height:192
	button btnAll "All" pos:[7,201] width:52 height:17
	button BtnNone "None" pos:[59,201] width:52 height:17
	button btnInvert "Invert" pos:[111,201] width:52 height:17

	on ListViewRo open do
	(
		setupList mLv
		displayListData mLv lvBits
	)
	on btnAll pressed do
		for i = 0 to mLv.items.count-1 do mLv.items.item[i].checked = true
	on BtnNone pressed do
		for i = 0 to mLv.items.count-1 do mLv.items.item[i].checked = false
	on btnInvert pressed do
		for i = 0 to mLv.items.count-1 do mLv.items.item[i].checked = not mLv.items.item[i].checked
)
createdialog ListViewRo style:#(#style_toolwindow,#style_sysmenu)

[font=Verdana][/font]

[font=Verdana]Do I have to test each item’s selected state in the listview, in order to get an array of all dotNetObjects selected?[/font]

err no

for i = 1 to listview.SelectedItems.count do
 	   theselecteditem = listview.SelectedItems.Item[i - 1];
 

theselecteditem is now a dotnet listviewitem
so for example you would call

theselecteditem.index

to get it’s list index

Thanks Pete,
the selection methods will defiantly help out.

Doh, Cheers Claude666
I was confusing myself with the listview.SelectedItems.Item[] and listview.Items.Item[]
Works great.
Cheers