DotNet ListView and AutoResizeColumn

Hello,

I have a dotNetControl ListView. I would like to use the method named AutoResizeColumn or AutoResizeColumns but I am stuck to use it.

The method is explained in the msdn documentation:
http://msdn.microsoft.com/en-us/library/system.windows.forms.listview%28...

Can someone help me to use it ?

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Rodman's picture

Here I come !

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)

Rodman

barigazy's picture

...

;)

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)

barigazy

Rodman's picture

:D

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

Rodman

barigazy's picture

...

post your code

barigazy

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.