Notifications
Clear all

[Closed] XtraTreeList getValue

 PEN

I have a bit of a problem with the code below and I’m trying all sorts of things to make it work. Run the code and then select a row and it will format the values to the listener. Notice that the values are float values. Not input a value in the second column either by the spinner or manually. Now select the rows and you can see that for the row you have picked the value is now returned as an integer.

What property am I missing to get the spinner to set a float value in the cell?

Note: Delete the space that CGT is adding for some reason in the line:
“DevExpress.XtraEditors.Repository.RepositoryItemSpinEdit”


   try(destroyDialog testR)catch()
   rollout testR "Test" 
   (
   	dotNetControl xtl "DevExpress.xtraTreeList.treeList" height:200
   	
   	fn initXtl xtl=
   	(
   		   xtl.OptionsSelection.MultiSelect = True
   		   xtl.OptionsView.ShowRoot =true
   		   xtl.OptionsView.ShowIndicator = false
   		   xtl.OptionsView.AutoWidth = true
   		
   		col=xtl.columns.add()
   		col.visible=true
   		col.width=120
   		col.caption="Items"
   		xtl.columns.item[0].fixed = xtl.columns.item[0].fixed.left
   		
   		local xTraSpinner=dotNetObject "DevExpress.XtraEditors.Repository.RepositoryItemSpinEdit"
   		xTraSpinner.SpinStyle=xTraSpinner.SpinStyle.vertical
   		xTraSpinner.minValue=0.0
   		xTraSpinner.maxValue=1.0
   		xTraSpinner.Increment=.1
   		xTraSpinner.UseCtrlIncrement=true
   		xTraSpinner.isFloatValue=true
   		xTraSpinner.AllowNullInput=xTraSpinner.AllowNullInput.false
   		xTraSpinner.nulltext="---  "
   		xtl.RepositoryItems.add xTraSpinner
   
   		col=xtl.columns.add()
   		col.visible=true
   		col.caption="Val:"
   		col.columnEdit=xTraSpinner
   		 col.UnboundType=col.UnboundType.Decimal
   	)
   	
   	fn addTargetNamesToEtl xtl theNodes:#("Test1","Test2","Test3")=
   	(
   		xtl.ClearNodes()
   		for i = 1 to theNodes.count do
   		(
   			n0=xtl.appendNode #(theNodes[i],0.5) -1
   				pos=xtl.appendNode #("Sub 1:",0.0) n0
   				rot=xtl.appendNode #("Sub 2:",0.0) n0
   		)
   	)
   
   	on xtl SelectionChanged senderArg arg do
   	(
   --			  formatProps senderArg
   		for i = 1 to senderArg.selection.count do
   		(
   			format "Index: % Value: % Display Text: %
" columnIndex (senderArg.selection.item[i-1].getValue 1) (senderArg.selection.item[i-1].GetDisplayText 1)
   		)
   		
   	)
   
   	on xtl CellValueChanged senderArg arg do
   	(
      		print (senderArg.selection.item[0].GetDisplayText 1)
   		 senderArg.selection.item[0].setvalue 1 ((senderArg.selection.item[0].GetDisplayText 1) as float)
   	)
   		
   	
   	on testR open do
   	(
   		initXtl xtl
   		addTargetNamesToEtl xtl
   	)
   )
   createDialog testR width:300 height:220
   
40 Replies

check changes in yellow:


try(destroyDialog testR)catch()
rollout testR "Test" 
(
	dotNetControl xtl "DevExpress.xtraTreeList.treeList" height:200
 
	fn initXtl xtl=
	(
		 xtl.OptionsSelection.MultiSelect = True
		 xtl.OptionsView.ShowRoot =true
		 xtl.OptionsView.ShowIndicator = false
		 xtl.OptionsView.AutoWidth = true
 
		col=xtl.columns.add()
		col.visible=true
		col.width=120
		col.caption="Items"
		xtl.columns.item[0].fixed = xtl.columns.item[0].fixed.left
 
		local xTraSpinner=dotNetObject "DevExpress.XtraEditors.Repository.RepositoryItemSpinEdit"
		xTraSpinner.SpinStyle=xTraSpinner.SpinStyle.vertical
		xTraSpinner.minValue=0.0
		xTraSpinner.maxValue=1.0
		xTraSpinner.Increment=.1
		xTraSpinner.UseCtrlIncrement=true
		xTraSpinner.isFloatValue=true
		xTraSpinner.AllowNullInput=xTraSpinner.AllowNullInput.false
		xTraSpinner.nulltext="--- "
		xtl.RepositoryItems.add xTraSpinner
 
		col=xtl.columns.add()
		col.visible=true
		col.caption="Val:"
		col.columnEdit=xTraSpinner
		 col.UnboundType=col.UnboundType.Decimal
	)
 
	fn addTargetNamesToEtl xtl theNodes:#("Test1","Test2","Test3")=
	(
		xtl.ClearNodes()
		for i = 1 to theNodes.count do
		(
			n0=xtl.appendNode #(theNodes[i],0.5,"") -1
				pos=xtl.appendNode #("Sub 1:",0.0,"") n0
				rot=xtl.appendNode #("Sub 2:",0.0,"") n0
		)
	)
 
	on xtl SelectionChanged senderArg arg do
	(
--			 formatProps senderArg
		for i = 1 to senderArg.selection.count do
		(
			format "Index: % Value: % Display Text: %
" columnIndex (senderArg.selection.item[i-1].getValue 1) (senderArg.selection.item[i-1].GetDisplayText 1)
		)
 
	)
 
	on xtl CellValueChanged senderArg arg do
	(
		print (senderArg.selection.item[0].GetDisplayText 1)
		 senderArg.selection.item[0].setvalue 1 ((senderArg.selection.item[0].GetDisplayText 1) as float)
	)
 
 
	on testR open do
	(
		initXtl xtl
		addTargetNamesToEtl xtl
	)
)
createDialog testR width:300 height:220

don’t ask me why… I have no idea (something about parenting an object)

 PEN

I don’t see any change in the behavior. If you set the value through the spinner and then try and get the value it is still returning an integer for me.

 PEN

Just ran into something else with this control. It looks as though the mouseUp event doesn’t work.

 PEN

Well it does fire but only if you are no over a row.

i will doublecheck it

here’s a final (my previous posts didn’t make any sense… sorry):


  try(destroyDialog testR)catch()
   rollout testR "Test" 
   (
   	dotNetControl xtl "DevExpress.xtraTreeList.treeList" height:200
   	local xTraSpinner
   	fn initXtl xtl=
   	(
   		   xtl.OptionsSelection.MultiSelect = True
   		   xtl.OptionsView.ShowRoot =true
   		   xtl.OptionsView.ShowIndicator = false
   		   xtl.OptionsView.AutoWidth = true
   		
   		col=xtl.columns.add()
   		col.visible=true
   		col.width=120
   		col.caption="Items"
   		xtl.columns.item[0].fixed = xtl.columns.item[0].fixed.left
	 
   xTraSpinner=dotNetObject "DevExpress.XtraEditors.Repository.RepositoryItemSp  inEdit"
   		xTraSpinner.SpinStyle=xTraSpinner.SpinStyle.vertic  al
   		xTraSpinner.minValue=0.0
   		xTraSpinner.maxValue=1.0
   		xTraSpinner.Increment=.1
   		xTraSpinner.UseCtrlIncrement=true
   		xTraSpinner.isFloatValue=true
   		xTraSpinner.AllowNullInput=xTraSpinner.AllowNullIn  put.false
   		xTraSpinner.nulltext="---  "
   		xtl.RepositoryItems.add xTraSpinner
   
   		col=xtl.columns.add()
   		col.visible=true
   		col.caption="Val:"
   		col.columnEdit=xTraSpinner
   		 col.UnboundType=col.UnboundType.Decimal
   	)
   	
   	fn addTargetNamesToEtl xtl theNodes:#("Test1","Test2","Test3")=
   	(
   		xtl.ClearNodes()
   		for i = 1 to theNodes.count do
   		(
   			n0=xtl.appendNode #(theNodes[i],0.5) -1
   				pos=xtl.appendNode #("Sub 1:",0.0) n0
   				rot=xtl.appendNode #("Sub 2:",0.0) n0
   		)
   	)

-- it's how documentation suggests to do
  on xtl CustomNodeCellEdit senderArg arg do if arg.node != undefined and arg.column != undefined and arg.node.selected do 
 (
  if arg.column.AbsoluteIndex == 1 do arg.RepositoryItem = xTraSpinner
 )
   
   	on xtl SelectionChanged senderArg arg do
   	(
   --			  formatProps senderArg
   		for i = 1 to senderArg.selection.count do
   		(
   			format "Index: % Value: % Display Text: %
" columnIndex (senderArg.selection.item[i-1].getValue 1) (senderArg.selection.item[i-1].GetDisplayText 1)
   		)
   		
   	)
   
   	on xtl CellValueChanged senderArg arg do
   	(
	  		print (senderArg.selection.item[0].GetDisplayText 1)
   		 senderArg.selection.item[0].setvalue 1 ((senderArg.selection.item[0].GetDisplayText 1) as float)
   	)
   		
   	
   	on testR open do
   	(
   		initXtl xtl
   		addTargetNamesToEtl xtl
   	)
   )
   createDialog testR width:300 height:220


Here’s my attempt:

if gItemHelperAssembly == undefined then
(
	global gItemHelperAssembly
)

-- Build up a snippet of code that will access the "Item[x]" pseudo-property of a dotNet object and return the value as a float.
fn newItemHelpers forceRecompile:false =
(
	if (forceRecompile or 
		(classof gItemHelperAssembly) != dotNetObject or 
		((gItemHelperAssembly.GetType()).ToString()) != "System.Reflection.Assembly") do
	(
		sb =  "using System;
"
		sb += "using System.Text;
"
		sb += "using System.Collections;
"
		sb += "using System.Reflection;
"
		
		sb += "class ItemHelpers
"
		
		sb += "{
"		
		sb += "  public Single GetFloatItem(Object tln, Int32 colId)
"
		sb += "  {
"				
		sb += "    Single ret = 0;
"
		sb += "    Object retObj;
"
		
		sb += "    try {
"
		
		sb += "      Type tlnType = tln.GetType();
"
		sb += "      MethodInfo mi = tlnType.GetMethod(\"get_Item\");
"		

		sb += "      Object[] parms = new Object[1];
"
		sb += "      parms[0] = colId;
"	
	
		sb += "      retObj =  mi.Invoke(tln,parms);
"
		
		sb += "    }
"
		
		sb += "    catch {
"
		sb += "      throw new System.Exception(\"GetFloatItem Error: Failed to invoke \\\"get_Item()\\\" method on input object\");
"
		sb += "    }
"
		
		sb += "    try {
"
		sb += "      ret = Convert.ToSingle(retObj);
"
		sb += "    }
"
		
		sb += "    catch {
"
		sb += "      StringBuilder err = new StringBuilder();
"
		sb +=  "     err.AppendFormat(\"GetFloatItem Error: Value in column {0} will not convert to a float!  Value: {1} Type: {2}\", colId, retObj, retObj.GetType() ); 
"
		sb += "      throw new System.Exception(err.ToString());
"
		sb += "    }
"
		
		sb += "    return ret;
"
		
		sb += "  }
"
			
		sb += "}
"

		csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
		compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
		
		-- Need to add referenced assemblies that the code snippet is 'using'
		compilerParams.ReferencedAssemblies.Add("System.dll");
		
		compilerParams.GenerateInMemory = true
		compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(sb)
		
		if (compilerResults.Errors.Count > 0 ) then
		(
			errs = stringstream ""
			for i = 0 to (compilerResults.Errors.Count-1) do
			(
				err = compilerResults.Errors.Item[i]
				format "Error:% Line:% Column:% %
" err.ErrorNumber err.Line \                                              
													 err.Column err.ErrorText to:errs 
			)
			MessageBox (errs as string) title: "Errors encountered while compiling C# code"
			format "%
" errs
			gItemHelperAssembly = undefined
			return undefined
		)
		else
		(
			gItemHelperAssembly = compilerResults.CompiledAssembly
		)
	)
	gItemHelperAssembly.CreateInstance "ItemHelpers"
)

   try(destroyDialog testR)catch()
   rollout testR "Test" 
   (
   	dotNetControl xtl "DevExpress.xtraTreeList.treeList" height:200
   	
	local ItemHelpers
	   
   	fn initXtl xtl=
   	(
		ItemHelpers = newItemHelpers()
		
		xtl.OptionsSelection.MultiSelect = True
   		xtl.OptionsView.ShowRoot =true
   		xtl.OptionsView.ShowIndicator = false
   		xtl.OptionsView.AutoWidth = true
   		
   		col=xtl.columns.add()
   		col.visible=true
   		col.width=120
   		col.caption="Items"
   		xtl.columns.item[0].fixed = xtl.columns.item[0].fixed.left
   		
   		local xTraSpinner=dotNetObject "DevExpress.XtraEditors.Repository.RepositoryItemSpinEdit"
   		xTraSpinner.SpinStyle=xTraSpinner.SpinStyle.vertical
   		xTraSpinner.minValue=0.0
   		xTraSpinner.maxValue=1.0
   		xTraSpinner.Increment=.1
   		xTraSpinner.UseCtrlIncrement=true
   		xTraSpinner.isFloatValue=true
   		xTraSpinner.AllowNullInput=xTraSpinner.AllowNullInput.false
   		xTraSpinner.nulltext="---  "
   		xtl.RepositoryItems.add xTraSpinner
   
   		col=xtl.columns.add()
   		col.visible=true
   		col.caption="Val:"
   		col.columnEdit=xTraSpinner
   		 col.UnboundType=col.UnboundType.Decimal
   	)
   	
   	fn addTargetNamesToEtl xtl theNodes:#("Test1","Test2","Test3")=
   	(
   		xtl.ClearNodes()
   		for i = 1 to theNodes.count do
   		(
   			n0=xtl.appendNode #(theNodes[i],0.5) -1
   				pos=xtl.appendNode #("Sub 1:",0.0) n0
   				rot=xtl.appendNode #("Sub 2:",0.0) n0
   		)
   	)
   
   	on xtl SelectionChanged senderArg arg do
   	(
   --			  formatProps senderArg
   		for i = 1 to senderArg.selection.count do
   		(
			valItm =  senderArg.selection.item[i-1].getValue 1
			txtItm =  senderArg.selection.item[i-1].GetDisplayText 1
			fltItm = ItemHelpers.GetFloatItem senderArg.selection.item[i-1] 1
   			format "Index: % Value: % Display Text: % Float Value: %
" columnIndex valItm txtItm fltItm
   		)
   		
   	)
   
   	on xtl CellValueChanged senderArg arg do
   	(
      		format "Display Text %
" (senderArg.selection.item[0].GetDisplayText 1)
			format "Value (as float) %
" (ItemHelpers.GetFloatItem senderArg.selection.item[0] 1)
   	)
   		
   	
   	on testR open do
   	(
   		initXtl xtl
   		addTargetNamesToEtl xtl
   	)
   )
   createDialog testR width:300 height:220
   
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

as I understood the problem is why “getvalue” method screws up…

 PEN

Thanks for the try again Denis but that produces the same result. To test it you need to change the value from .5 to some thing else and then try and get the value from the cell. What you get is an integer returned.

Thanks Mike, you have the solution, I would have never got there that is for sure. Once I’m done this project I would like to document some of my findings on my site about the xrtraTreeList control as well as this code snippet, would that be OK with you?

you right… in my code “getvalue” screws up too after the change/select combination

Page 1 / 3