DataGridView Checkbox

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 12 December 2008   #1
DataGridView Checkbox

I can't seem to figure out whether a checkbox in a checkbox column in a DataGridView is checked or not, it doesn't have any property I can access that I can see. Everything seems to be working correctly (event handlers, etc), but I can't see whether a checkbox is checked or not. If more info is needed, will provide, but I figure this shouldn't be too difficult for anyone that knows more than I.
__________________
Tech-Artists.Org, a Community for Technical Artists

www.robg3d.com
 
Old 12 December 2008   #2
presuming...

dgv = the data grid view
cell = the DataGridViewCheckBoxCell (from column type DataGridViewCheckBoxColumn)


Then you can use cell.value to get the boolean state of that cell.

One word of warning - it does not reflect the user-edited state of the cell while the user is still editing the cell. The typical way of handling this is by using the events to drive any variables or states required. If you have to handle it via an outside event - say another dialog, or a rollout button or whatever - then you can first commit any edits the user may have made using dgv.commitEdit (dotNetClass "DataGridViewDataErrorContexts").commit . There's some quirks with this - e.g. cell.isInEditMode will happily remain true even though the UI no longer shows this, so if at all possible - handle it via the actual event.
 
Old 01 January 2009   #3
dgv
dotNetControl:dgv:System.Windows.Forms.DataGridVie  w
dgv.columns.item[0]
dotNetObject:System.Windows.Forms.DataGridViewChec  kBoxColumn
dgv.rows.item[0].cells.item[0]
dotNetObject:System.Windows.Forms.DataGridViewChec  kBoxCell
dgv.rows.item[0].cells.item[0].value
""

(I don't know why the spacing is messed up)
Unless I'm doing something wrong, value is returning a string value... I cannot seem to access the boolean state (and as you can see, it is definitely a checkboxcell and in a checkboxcolumn).

And thanks for the warning- I gathered there'd be a gotcha from the MSDN reference, but I can't even get the checkbox state yet!
__________________
Tech-Artists.Org, a Community for Technical Artists

www.robg3d.com
 
Old 01 January 2009   #4
haven't the foggiest - try checking .valueType or, in fact, try a showProperties on the cell.. that should reveal the type returned by .value as well.

The below code should work:

rollout roll_test "test" width:256 height:256 (		
	dotnetcontrol dnc_dgv "System.Windows.Forms.DataGridView" width:200 height:200 pos:[8,8]
	button btn_printval "print value of topleft cell"

	on roll_test open do 	(
		local dno_ckb_column = dotNetObject "DataGridViewCheckBoxColumn"
		dno_ckb_column.headerText = "test"

		dnc_dgv.columns.add dno_ckb_column
		
		boolVal = if ((maxVersion())[1] < 11000) then ( dotNetObject "System.Boolean" true ) else ( true )
		for i = 1 to 3 do (
			dnc_dgv.rows.add #(boolVal)
		)
	)
	on btn_printval pressed do (
		dnc_dgv.commitEdit (dotNetClass "DataGridViewDataErrorContexts").commit
		format "Value: %\n" dnc_dgv.rows.Item[0].Cells.Item[0].value
	)
)
createdialog roll_test
 
Old 01 January 2009   #5
Haha, well that's funny enough. Where you had:
dnc_dgv.rows.add #(dotNetObject "System.Boolean" true)

I was essentially doing:
dnc_dgv.rows.add #(dotNetObject "System.String" "")

(The rest of the row are strings, so I just set the first one (the checkbox) as an empty string). It appears setting its value as a string when you add the checkbox column messes it up, permanently (setting a cell's value to a .net string after the fact doesn't seem to mess it up permanently). Harumph, what a stupid bug (it should really throw an exception or just revert it to a boolean, like it does when you try to change it after the fact).

Thanks Zeboxx, for yet another snip of demo code!
__________________
Tech-Artists.Org, a Community for Technical Artists

www.robg3d.com
 
Old 01 January 2009   #6
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 08:44 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.