Notifications
Clear all

[Closed] dotNetObject "System.Data.DataTable" problem when added too many columns

Hi!

I found thie piece of code here.

(
	global main;
	global theUI;
	global theDialog;
	
	struct theUIStr
	(
		dgvMain = dotnetobject "system.windows.forms.dataGridView",
		dtMain = dotNetObject "System.Data.DataTable"
	)
	
	struct mainSTR
	(
		ColorClass = DotNetClass "System.Drawing.Color",
		lbBackColor = ColorClass.black,
		
		fn addColumns  =
		( 
			theUI.dtmain.columns.clear() 
			theUI.dtmain.BeginInit()
			theUI.dtmain.BeginLoadData()
			
			for c = 1 to 1000 do
			(
				f = theUI.dtmain.columns.add (c as string) (dotnet.getType "System.String") 
-- 				f.FillWeight = 1
-- 				if c == 1 f.frozen = true 
			)
			theUI.dtmain.EndLoadData()
			theUI.dtmain.EndInit()
			
		),			
		
		fn addRows =
		( 	
			theUI.dtmain.BeginInit()
			theUI.dtmain.BeginLoadData()
			theUI.dtmain.rows.clear()
			theUI.dtmain.loaddatarow #("abc") true
			theUI.dtmain.loaddatarow #("aabc") true
			theUI.dtmain.loaddatarow #("aaabc") true
			theUI.dtmain.loaddatarow #("aaaabc") true
			theUI.dtmain.loaddatarow #("aaaaabc") true			
			theUI.dtmain.endloaddata()
			theUI.dtmain.EndInit()
		),
		
		fn formatDgv =
		(			
			theUI.dgvmain.DataSource = theUI.dtMain
		),
				
		fn updateDgv = 
		(
			theUI.dgvMain.suspendlayout()
			main.addColumns () 
			main.addRows () 
			main.formatDgv()			
			theUI.dgvMain.invalidate()
			theUI.dgvMain.resumelayout()
		),
		fn onDgvCellEndEdit s e=
		(
			main.updateDgv()
		),
		fn start =
		(
			dotnet.addEventHandler theUI.dgvmain "CellEndEdit" onDgvCellEndEdit
			main.updateDgv()
		)
	)

	rollout theDialog "theDialog"
	(
		
		dotNetControl form "UserControl" height:200 width:850
		
		fn positionElements = 
		(
			local margin = 			4
			local mainW          =	theDialog.width-margin;
			local mainH          = 	theDialog.height-margin;
			form.width = 		mainW
			form.height = 		mainH
			
		)
		fn formatUI = 
		(	
			local margin = 			4
			form.controls.add theUI.dgvmain
			theUI.dgvmain.width=theDialog.Form.width-margin;
			theUI.dgvmain.height=theDialog.Form.height-margin;
		)
		on theDialog open do
		(
			theDialog.form.hide()
			theUI = theUISTR()
			main = mainSTR()
			formatUI()	
			theDialog.form.show()		
			main.start() 
		)
	)
	
	CreateDialog theDialog 860 210 pos:[25, 25] style:#(#style_toolwindow, #style_sysmenu, #style_resizing)
	
)

It works as expected, but when I try to add 1000 rows an error occurs:

-- Runtime error: .NET runtime exception: Sum of the columns' FillWeight values cannot exceed 65535.

I know how to solve this problem when the regular “system.windows.forms.dataGridView” is used – I have to set the FillWeight = 1 for every column.
But I don’t know how to do the same in the code above.
I also need the first and the second column to stay frozen. In the code there are comented line that works but for regular “system.windows.forms.dataGridView” when columns are added.

I have checked the properties of the “dataTable” and “dataColumn” but there is nothlng that will freeze the added column or will set its FillWeight to 1.

Is there are a solutions to my problems?