Autoresize listview dotnet (SOLVED)


#1

I have a script that is using a dotnet listview and im trying to find a way to make the list resize automatically when resizing the window.

I’ve searched online and couldn’t really find any solution, i would be grateful if anyone could help me with this.

 (

--Destroy dialog if it already exists.
try(destroyDialog quickStat)catch()

	
--Create a rollout
rollout quickStat "Texture Checker" width:820

(
	
	--Create the dotNet listview control
dotNetControl lv "system.windows.forms.listView" pos: [12,40] height:400 width:800


 fn compileListItemSorter =
(
    source =  "using System;\n"
    source += "using System.Windows.Forms;\n"
    source += "using System.Collections;\n"
    source += "class ListViewItemComparer : IComparer\n"
    source += "{\n"
    source += "    private int c;\n"
    source += "    private bool num = false;\n"
    source += "    private int dir = 1;\n"
    source += "    public ListViewItemComparer() { c = 0; }\n"
    source += "    public ListViewItemComparer(int column, bool numeric, bool reverse)\n"
    source += "    { c = column; num = numeric; dir = reverse ? -1 : 1; }\n"
    source += "    public int Compare(object x, object y)\n"
    source += "    {\n"
    source += "        if (num) return Convert.ToInt32(((ListViewItem)x).SubItems[c].Text).CompareTo(\n"
    source += "            Convert.ToInt32(((ListViewItem)y).SubItems[c].Text)) * dir;\n"
    source += "        else return String.Compare(((ListViewItem)x).SubItems[c].Text,\n"
    source += "            ((ListViewItem)y).SubItems[c].Text) * dir;\n"
    source += "    }\n"
    source += "}"

    local csharpProvider = dotNetObject "Microsoft.CSharp.CSharpCodeProvider"
    local compilerParams = dotNetObject "System.CodeDom.Compiler.CompilerParameters"
    compilerParams.GenerateInMemory = true
    compilerParams.ReferencedAssemblies.Add("System.Windows.Forms.dll")
    compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)
    compilerResults.CompiledAssembly
	
)
	

--Innitialize the listview control
fn initLv theLv=
(
	--Setup the forms view
	theLv.view=(dotNetClass "system.windows.forms.view").details
	theLv.FullRowSelect=true		--Set so full width of listView is selected and not just first column.
	theLv.GridLines=true			--Show lines between the items. 
	theLv.MultiSelect=true			--Allow for multiple selections. 
	theLv.AllowColumnReorder = true
	theLv.AllowColumnReorder = true
	theLv.autoResizeColumn
	
	

		
	theLv.backColor=lv.backColor.FromArgb 250 250 210 -- Soften the background intensity a bit
		


)



--Add columns. 
   fn addColumns theLv columnsAr=
(
	theLv.columns.add columnsAr[1] 120 	-- object name
    theLv.columns.add columnsAr[2] 120	-- materialname
    theLv.columns.add columnsAr[3] 120		-- Diffuse-map
	theLv.columns.add columnsAr[4] 120		-- Opacity-map
	theLv.columns.add columnsAr[5] 120		-- specular-map
	theLv.columns.add columnsAr[6] 120		-- glossiness-map
	theLv.columns.add columnsAr[7] 120		-- Bump-map
	theLv.columns.add columnsAr[8] 120		-- Ambient-map
	theLv.columns.add columnsAr[9] 120		-- speclevel-map
	theLv.columns.add columnsAr[10] 120		-- selfillumination-map
	theLv.columns.add columnsAr[11] 120		-- filtercolor-map
	theLv.columns.add columnsAr[12] 120		-- reflection-map
	theLv.columns.add columnsAr[13] 120		-- refraction-map
	theLv.columns.add columnsAr[14] 120		-- displacement-map
	

)


			
--Adds rows of data to the listView
fn populateList theLv=
(
	rows=#()		--Empty array to collect rows of data
	for x in objects do		--Loop through all the objects in the scene. 
	(
	
		li=dotNetObject "System.Windows.Forms.ListViewItem" x.name	-- column 1 :: 	--Create a listViewItem object and name it. 
		li.subitems.add((x.material.name) as string)										-- column 2 :: Add or remove ".name" to show or hide material type e.g. vray/standard
		li.subitems.add (try((filenamefrompath (x.material.diffusemap.filename )) as string)catch("--"))										-- column 3 :: Adds difuse map texture name
		li.subitems.add (try((filenamefrompath (x.material.opacitymap.filename)) as string)catch("--"))										-- column 4 :: Adds opacity map texture name
		li.subitems.add (try((filenamefrompath (x.material.specularMap.filename)) as string)catch("--"))
		li.subitems.add (try((filenamefrompath (x.material.glossinessMap.filename)) as string)catch("--"))
		li.subitems.add (try((filenamefrompath (x.material.bumpmap.filename)) as string)catch("--"))
		li.subitems.add (try((filenamefrompath (x.material.ambientmap.filename)) as string)catch("--"))
		li.subitems.add (try((filenamefrompath (x.material.specularLevelmap.filename)) as string)catch("--"))
		li.subitems.add (try((filenamefrompath (x.material.selfIllummap.filename)) as string)catch("--"))
		li.subitems.add (try((filenamefrompath (x.material.filtermap.filename)) as string)catch("--"))
		li.subitems.add (try((filenamefrompath (x.material.reflectionmap.filename)) as string)catch("--"))
		li.subitems.add (try((filenamefrompath (x.material.refractionmap.filename)) as string)catch("--"))
		li.subitems.add (try((filenamefrompath (x.material.displacementmap.filename)) as string)catch("--"))				
							


		li.Tag = dotnetMXSValue x
		
		append rows li		--Added the listViewItem to the rows array
	)
	theLv.items.addRange rows		--Add the array of rows to the listView control. 
)



on lv columnClick columnHeader do
	(
   	lv.ListViewItemSorter = dotnetobject "MXS_dotNet.ListViewItemComparer" columnHeader.column
		lv.ListViewItemSorter = undefined
	)



on refresh pressed do
	(
	lv.items.clear()
	initLv lv
	populateList lv
	)

	
on colstack pressed do
(
	for o in selection do
		(
			converttopoly o
		)
)


on lv ItemSelectionChanged s a do
	(
		format "item:% selected:% node:%\n" a.item.text a.isSelected a.item.tag.value 
	)
			

on lv SelectedIndexChanged s a do
	(
		with undo off 
		(
			nodes = for k=0 to s.selectedItems.count-1 where isvalidnode (node = s.selectedItems.item[k].tag.value) collect node
			if nodes.count == 0 then clearselection() else select nodes
		)
	)


on lv MouseDoubleClick arg do 
	(
		hit=(lv.HitTest (dotNetObject "System.Drawing.Point" arg.x arg.y))
    row=hit.item.Index
    colAdd=(if (mod row 2)==0 then 20 else -20)
		 lv.items.item[row].BackColor=lv.items.item[row].BackColor.fromARGB (220+colAdd) (100+colAdd) (100+colAdd)
	)

on quickStat open do
(
	initLv lv
	addColumns lv #("Objectname","Materialname","Diffuse-map","Opacity-map","Specular-map","Glossiness-map","Bump-map","Ambient-map","SpecLevel-map","Self-Illum-map","Filter-map","Refl-map","Refra-map","Displace-map")
	populateList lv
)

	
)

--Create a dialog and assign the rollout to it. 
createDialog quickStat style:#(#style_titlebar, #style_sysmenu, #style_resizing)
)

#2
on quickStat resized size do
	(
		lv.width = size.x - 20
		lv.height = size.y - 40
		-- or this
		-- lv.size = dotNetObject "System.Drawing.Size" (size.x-20) (size.y-40)

	)

#3

@miauu SOLVED! I love you.