Notifications
Clear all

[Closed] dotNet dataGridView can't make it editable

 PEN

What on earth am I missing? I can’t make the cells editable. I need to have this running in a Max Script rollout as I already have. Way to big a tool to be changing the UI at this time.


try(destroyDialog toolTest.testR; toolTest.testR=undefined)catch()
struct toolTest
(
	testR=undefined,
	
	fn beginEdit sender arg = 
	(
		print sender
		sender.beginEdit true 
	),

	fn init cont=
	(
		clearListener()
		cv=dotNetObject "dataGridView"
		
		cv.RowHeadersVisible=false
		cv.AutoSizeColumnsMode=cv.AutoSizeColumnsMode.fill
		cv.AllowUserToAddRows=false
		cv.ShowEditingIcon=false
		cv.dock=cv.dock.fill
		cv.ReadOnly=false
		
		col=dotNetObject "DataGridViewTextBoxColumn"
		col.HeaderText="Name"
		cv.columns.add col

		col=dotNetObject "DataGridViewTextBoxColumn"
		col.HeaderText="End Frame"
		col.valueType=dotNetClass "System.Single"
		cv.columns.add col

		cont.controls.add cv
		
		cv.rows.clear()
		for i= 1 to 5 do
		(
			row=dotNetObject "dataGridViewRow"
			cv.rows.add row
			
			row.cells.item[0].value=""
			row.cells.item[1].value=(animationRange.start as integer)/ticksPerFrame
			
		)
		
		dotNet.addEventHandler cv "mouseDown" beginEdit
		dotNet.setLifeTimeControl cv #dotNet

	),
	
	fn ui=
	(
		rollout testR "Test" width:200
		(
			dotNetControl cont "containerControl" width:(testR.width-20) height:100
			
			on testR open do 
			(
				toolTest.init cont
			)
		)
	),
	
	fn run=
	(
		if testR==undefined then
		(
			testR=ui()
			createDialog testR
		)else
		(
			destroyDialog testR
			testR=undefined
		)
	)
)
toolTest=toolTest()
toolTest.run()


11 Replies
 PEN

Another odd one that I’m running into. I’m using DataGridViewCheckBoxColumn and the mouseUp event on the dataGridView to fire the clicking on it. As long as I click in that cell the value that is returned is what it previously was, not what I have set it to.

For instance. If the checkBox was false and I click on the checkBox and set it to true it returns false. This holds true even if I don’t click on the actual box but beside it. I need to click on another cell to get the value that I have set. What gives?

why it doesn’t go to edit?

it’s because of max accelerators… you have to turn them off and on back. the good places are CellBeginEdit and CellEndEdit events

try(destroyDialog toolTest.testR; toolTest.testR=undefined)catch()
struct toolTest
(
	testR=undefined,
	
	fn beginEdit s a = 
	(
		format "start edit % %
" s a
		enableAccelerators = off
	),
	fn endEdit s a = 
	(
		format "end edit % %
" s a
		enableAccelerators = on
	),

	fn init cont=
	(
		clearListener()
		cv=dotNetObject "dataGridView"
		
		cv.RowHeadersVisible=false
		cv.AutoSizeColumnsMode=cv.AutoSizeColumnsMode.fill  
		cv.AllowUserToAddRows=false
		cv.ShowEditingIcon=false
		cv.dock=cv.dock.fill
		cv.ReadOnly=false
		
		col=dotNetObject "DataGridViewTextBoxColumn"
		col.HeaderText="Name"
		cv.columns.add col

		col=dotNetObject "DataGridViewTextBoxColumn"
		col.HeaderText="End Frame"
		col.valueType=dotNetClass "System.Single"
		cv.columns.add col

		cont.controls.add cv
		
		cv.rows.clear()
		for i= 1 to 5 do
		(
			row=dotNetObject "dataGridViewRow"
			cv.rows.add row
			
			row.cells.item[0].value=""
			row.cells.item[1].value= random 1 100 --(animationRange.start as integer)/ticksPerFrame is the same as animationRange.start.frame as integer
		)
		
		dotnet.addEventHandler cv "CellBeginEdit" beginEdit
		dotnet.addEventHandler cv "CellEndEdit" endEdit
		
		--dotNet.addEventHandler cv "mouseDown" beginEdit
		--dotNet.setLifeTimeControl cv #dotNet

	),
	
	fn ui=
	(
		rollout testR "Test" width:200
		(
			dotNetControl cont "containerControl" width:(testR.width-20) height:100
			
			on testR open do 
			(
				toolTest.init cont
			)
		)
	),
	
	fn run=
	(
		if testR==undefined then
		(
			testR=ui()
			createDialog testR
		)else
		(
			destroyDialog testR
			testR=undefined
		)
	)
)
toolTest=toolTest()
toolTest.run()

after that you have to control what characters user types…
there are several ways to do it. for example add validator to edit control, control key press event, etc.
the KeyPress event is most used usually because you have to control Return (to confirm) and Esc (to escape, resume) pressed

also it’s a good idea to control cell’s edit control events … specially TextChanged. it’s would help in case when text pasted to the control using ‘clipboard’

about check boxes… probably the CellValueChanged event will be the best signal to get the recent value (as well as the previous)

if you want to ‘commit’ for any reason the changing before focus leaves the control you can use CurrentCellDirtyStateChanged event

 PEN

Thanks I will give those a try. Tried the accelerators but didn’t get it working, will try can the events and see what happens.

what is not working?

here is a fully working example:

try(destroyDialog dgvDialog) catch()
rollout dgvDialog "DataGridView" width:200 height:300
(
	fn onCellBeginEdit s e = 
	(
		format "start edit >> % %
" s e
		enableAccelerators = off
	)
	fn onCellEndEdit s a = 
	(
		format "end edit >> % %
" s e
		enableAccelerators = on
	)
	fn onEditingControlShowing s e =
	(
		fn onEditKeyPress s e = 
		(
			char = e.get_KeyChar asdotnetobject:on
			if not ((dotnetclass "System.Char").IsControl char) and not ((dotnetclass "System.Char").IsDigit char) do
			(
				e.Handled = on
			)
		)
		edt = e.Control
		dotnet.addEventHandler edt "KeyPress" onEditKeyPress
	)
	
	dotnetcontrol panel "ContainerControl" width:190 height:290 pos:[5,5]
	
	fn initDGV panel =
	(
		dgv = dotnetobject "DataGridView"
		
		dgv.RowHeadersVisible = off
		dgv.AutoSizeColumnsMode = dgv.AutoSizeColumnsMode.Fill    
		dgv.AllowUserToAddRows = off
		dgv.ShowEditingIcon = off
		dgv.Dock = dgv.Dock.Fill
		dgv.ReadOnly = off
		
		col = dotnetobject "DataGridViewTextBoxColumn"
		col.HeaderText = "Name"
		dgv.columns.add col

		col = dotnetobject "DataGridViewTextBoxColumn"
		col.HeaderText = "End Frame"
		col.ValueType = dotnetclass "System.Single"
		dgv.columns.add col
		
		for i = 1 to 5 do
		(
			row = dotnetobject "DataGridViewRow"
			dgv.rows.add row
			
			row.cells.item[0].value = ""
			row.cells.item[1].value = random 1 100
		)
		
		dotnet.addEventHandler dgv "CellBeginEdit" onCellBeginEdit
		dotnet.addEventHandler dgv "CellEndEdit" onCellEndEdit
		dotnet.addEventHandler dgv "EditingControlShowing" onEditingControlShowing
		
		panel.Controls.Add dgv 
		
		dgv
	)
				
	on dgvDialog open do 
	(
		initDGV panel
	)
)
createdialog dgvDialog

also it shows how to filter only digits in text column

 PEN

Example works fine, for some strange reason can’t get it to work in my tool and it isn’t much different from what you have.

 PEN

And as I posted that I realized my stupidity.

Thanks for the help Denis.

 PEN

CellValueChanged isn’t working as it should. Strange the way it gets called. I can toggle the first checkbox on and off and it doesn’t call the event. Move to the second and it does but just once.

Page 1 / 2