Notifications
Clear all

[Closed] Treeview Checked node Selection in dotnet

Does anybody know how to print the text of the node when that item is checked?
I am a newbie in using dotnet with maxscript.

Here is my code as of now.

(
clearListener()
local rootObjs=#()

local tvObjs = dotNetObject “System.windows.forms.treeview”
tvObjs.text= “Objects On Scene”
tvObjs.size= dotNetObject “System.Drawing.Size” 200 200
tvObjs.location=dotNetObject “System.Drawing.Point” 20 30

local chkObjs = dotNetObject “System.windows.forms.checkbox”

local hForm = dotNetObject “System.Windows.Forms.Form”
hForm.size = dotNetObject “System.Drawing.Size” 500 300
hForm.TopMost=true
hForm.controls.add tvObjs

fn findRootObjs=
(
rootObjs=#()
for o in objects do
(
if o.parent==undefined then append rootObjs o
)
)

fn recurseHierarchy obj treeNode=
(
for i = 1 to obj.children.count do
(
recurseNode= (dotNetObject “System.Windows.Forms.TreeNode” obj.children[i].name)
treeNode.nodes.add recurseNode
recurseHierarchy obj.children[i] recurseNode
)
)

fn populateTreeView=
(
findRootObjs()
for x in rootObjs do
(
newNode=(dotNetObject “System.Windows.Forms.TreeNode” x.name)
tvObjs.nodes.add newNode
recurseHierarchy x newNode
)
)
fn nodesSelected=
(
print tvObjs.selectedNode.text
if (getNodeByName tvObjs.selectedNode.text).IsSelected then
(
deselect (getNodeByName tvObjs.selectedNode.text)
)
Else
(
selectmore (getNodeByName tvObjs.selectedNode.text)
–sel=for o in selection collect o
)
if zoomChk==true then
(
max zoomext sel
)
)
fn nodesChkd=
(
print tvObjs.selectedNode.text
)

fn formLoad=
(
clearListener()
populateTreeView()
tvObjs
tvObjs.checkboxes=true
)

dotNet.addEventHandler hForm “Load” formLoad
dotNet.addEventHandler tvObjs “AfterSelect” nodesSelected
dotNet.addEventHandler tvObjs “AfterCheck” nodesChkd

hForm.show()
ok
)

Thank you
Sumesh

5 Replies
fn nodesChkd args=
(
	print args.node.text
)

Thanks Akram. Is it possible to highlight the node when that node is checked and vice versa?

Thanks
Sumesh

Yes that can be done, you can use the args, which is the treenode and set its checked property.


arg.node.checked=True --add this to the nodesSelected function with args as argument

fn nodesChkd args=
(
	print args.node.text
	tvObjs.selectedNode=args.node
)

Thanks Akram, that worked.

How do we have a node checked on startup? I am trying to use the IsSelected property of an object to check whether it is selected on scene and accordingly select the corresponding node in the treeview. Somehow i was able to highlight the node but not check it.