Notifications
Clear all

[Closed] dotnet listview items

I have a script here

thePath = getsavePath()
   if thePath != undefined do
   (
   	theFiles = getFiles (thePath+"\\*.max") --
   rollout DE_Dl3 "Untitled" width:460 height:480
   (
   	--Create the dotNet listview control
   	label lb3 "1 / Check files to delete" pos:[18,10] height:25
   	dotNetControl lv "system.windows.forms.listView" height:400
   	button del "2 / Delete the files checked" width:200 height:21 pos:[18,450]
   	fn initLv Lv =
   	(
   	--Setup the forms view
   	Lv.view=(dotNetClass "system.windows.forms.view").details
   	Lv.FullRowSelect=true		--Set so full width of listView is selected and not just first column.
   	Lv.GridLines=true			--Show lines between the items. 
   	Lv.MultiSelect=true			--Allow for multiple selections. 
   	Lv.Checkboxes = true
   	)
   								
   	--Add columns. 
   	fn addColumns Lv columnsAr=
   	(
   		w=(Lv.width/columnsAr.count)-1		--Calculate the width of each column.
   		for x in columnsAr do		--Loop through all the column names to be added. 
   		(
   			Lv.columns.add x w		--Add each new column to the listview control. 
   		)
   	)
   									
   									--Adds rows of data to the listView
   	fn populateList Lv=
   	(
   		rows=#()		--Empty array to collect rows of data
   		for f in theFiles do		--Loop through all the objects in the scene. 
   		(									
   			filename = filenameFromPath f
   			li=dotNetObject "System.Windows.Forms.ListViewItem" filename		--Create a listViewItem object and name it. 
   			li.subitems.add (((GetFileSize f)/1024)  as string + " KB")		  --Add data to the second column.
   			append rows li		--Added the listViewItem to the rows array
   											
   		)
   		Lv.items.addRange rows		--Add the array of rows to the listView control. 
   	)
   	on DE_Dl3 open do
   	(
   		initLv Lv
   		addColumns Lv #("File name","Size")
   		populateList Lv
   	)
   		
   	on del pressed do
   	(
   		for  i = 1 to Lv.items.count do
   		(
   			if Lv.items.item[i].Checked == true do
   			(
   			print i
   			)
   	)
   	destroyDialog DE_Dl3
   )
   )	
   createDialog DE_DL3
   						
   )						
  

I want pressed del button then script delete the file selected

Who can help me ?
thanks !

8 Replies
for i = lv.selecteditems.count to 1 by -1 do
   (
   --delete the max file..
   [b]deleteFile[/b] a.tag
   lv.Items.Remove(lv.selecteditems.item[i-1])
  )

Something like this?..

edit: Although I’ve used this multiselect and without checkboxes so might need to be different with checkboxes…

can you make a script access the files selected ?

when we click on the botton below, the script will process the selected files. for example: ” check keys on those one”

I recommend the same solution as Io.
I have a datagridview with that and works smoothly (and at the beginning that script was a listview and it needed that functionality).

Ohhh This is handy! every time I change a listViews column back color the entire row back color changes haven’t found a way around it ( or have I spent much time trying to figure it out)

 lo1

You must set UseItemStyleForSubItems to false for each ListViewItem

This might be useful:
http://forums.cgsociety.org/showthread.php?t=1210536

UseItemStyleForSubItems was the setting I needed. Thx guys!