ScriptSpot

Forum topic · General Scripting

DotNet ListView and AutoResizeColumn

By Rodman · 2013-11-29

Description
Comments (4)

Here I come !

Rodman · 2013-12-02


rol_Test
try(destroyDialog rol_Test)catch()

rollout rol_Test "Test"
(
	dotNetControl lv "system.windows.forms.listView" pos:[5,5] width:300 height:200
	
	function InitLv theLv =
	(
		theLv.view = (dotNetClass "system.windows.forms.view").details
	)

	fn AddColumns theLv columnsAr =
	(
		theLv.columns.add columnsAr[1] 100
		theLv.columns.add columnsAr[2] 300
	)
	
	fn PopulateList theLv arr =
	(
		rows=#()
		for t = 1 to arr.count do
		(
			li = dotNetObject "System.Windows.Forms.ListViewItem" (arr[t][1])
			li.UseItemStyleForSubItems = true
			
			li.subitems.add arr[t][2]
		   
			append rows li
		)
		
		theLv.items.addRange rows
		theLv.Update()
	)
	
	on rol_Test open do
	(  
		InitLv lv
		AddColumns lv #("Column 1", "Column 2")
		
		local arr = #()
		for i = 1 to 9 do arr[i] = #(i as string, "i am a very long string and this is what i am, don't be maaaaaaaaaaad !")
		
		PopulateList lv arr
		
		-- I can't solve this part
		--------------------------------------------------------------------------------------------------------------------------------------------------------------
		-- lv.columns.AutoSizeMode  = (dotNetClass "system.windows.forms.columnheader").AutoResize
		--------------------------------------------------------------------------------------------------------------------------------------------------------------
	)
)
createDialog rol_Test 510 210 style:#(#style_titlebar, #style_sysmenu, #style_resizing)

barigazy · 2013-12-02

;)

Cheers!

try(destroyDialog ::rol_Test)catch()
rollout rol_Test "Test"
(
-- the next fn is only for testing
--------------------------------------------------------------------------- random file generator
fn randomVFGen cnt: viritualPathName: =
(
local sioPath = dotNetClass "System.IO.Path"
for i = 1 to cnt collect viritualPathName + "\\" + sioPath.GetRandomFileName()
)
----------------------------------------------------------------------------

fn defColor r g b = ((dotNetClass "System.Drawing.Color").FromArgb r g b)
local maxBC = defColor 60 60 60, maxFC = defColor 200 200 200
fn autoResizeColumn lv columns: =
(
vScrollWidth = 21 -- vertical scrollbar width
for c = 0 to columns-1 do
(
lv.AutoResizeColumn c (dotNetClass "ColumnHeaderAutoResizeStyle").ColumnContent
vScrollWidth += lv.Columns.Item[c].Width
) ; vScrollWidth
)
fn AddColumns theLv columnsAr =
(
for i in 1 to columnsAr.count do theLv.columns.add columnsAr[i] 0
)
fn PopulateList theLv arr =
(
rows=#()
for t = 1 to arr.count do
(
li = dotNetObject "ListViewItem" (formattedPrint t format:"0.4d")
li.UseItemStyleForSubItems = true
li.subitems.add arr[t]
append rows li
)
theLv.items.addRange rows
theLv.Update()
)
dotNetControl lv "ListView" pos:[5,5] --width:300 height:200
on rol_Test open do
(
lv.backcolor = maxBC ; lv.forecolor = maxFC
lv.view = (dotNetClass "View").details
lv.HideSelection = true ; lv.height = 200
AddColumns lv #("No.", "Virtual Files")
PopulateList lv (randomVFGen cnt:30 viritualPathName:@"C:\temp\viritualFileNameCollections\")
lv.width = autoResizeColumn lv columns:2
)
)
createDialog rol_Test 400 210 style:#(#style_titlebar, #style_sysmenu, #style_resizing)

:D

Rodman · 2013-12-02

Thank you Branko !!! Can't wait to try it ! It looks goooood ! :)

barigazy · 2013-11-29

post your code