Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed Post any question regarding Basic4ppc.


Unable to cast Object Treeview.node


Reply
 
LinkBack Thread Tools Display Modes
  #11 (permalink)  
Old 03-21-2008, 12:58 AM
RandomCoder's Avatar
Basic4ppc Veteran
 
Join Date: May 2007
Location: UK
Posts: 486
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Quote:
Originally Posted by Mr_Gee View Post
Well I replaced the sub with your version, the error doesn't show in the IDE,
but after i compile it I get the Treeview.Treeview and Treeview.node error again
Just out of interest, try replacing all instances of Control(node,treeview) with Control(node,treeview.ControlRef)

I don't know if this will do the trick but it helped when I had a similar problem adding a context menu to a treeview control.

Regards,
RandomCoder
__________________
Desktop: Pentium D 920 (2.8GHz, 4MB L2 Cache, 800MHz FSB), 1024MB, 256MB Radeon X600, 250GB HD.
Device : Axim X51v XScale 624MHz, 3.7" VGA, 64MB SDRAM, 256MB Flash ROM + 1Gb SD.

"Defeat never comes to any man until he admits it."Josephus Daniels
Reply With Quote
  #12 (permalink)  
Old 03-21-2008, 10:05 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,770
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

I've cracked it. I didn't look closely enough at what happens after the first call to Findfolders. First time parameter "node" is a TreeView, other times it is a Node. You need a conditional test to find out which. Note the type name of a Node as returned by ControlType is "Treeview.Node". You may need to try with a msgbox to see what is returned for other external controls.

Code:
Sub FindFolders (path, node) 'Finds all folders in a specific path
	WaitCursor(true)
	al1.clear
	DirSearch(al1,path)
	c = StrLength(path)
	For I =0 To al1.count - 1
		s=al1.item(i)
		If ControlType(node) = "TreeView.Node" Then
			Control(node, node).addnewnode (SubString(s,c,StrLength(s)-c))
		Else
			Control(node, treeview).addnewnode (SubString(s,c,StrLength(s)-c))	
		End If
	Next
	al1.Clear
	FileSearch(al1,path)
	For I =0 To al1.count - 1
		s=al1.item(i)
		If ControlType(node) = "TreeView.Node" Then
			node2.Value = Control(node,node).addnewnode (SubString(s,c,StrLength(s)-c))
		Else
			node2.Value = Control(node,treeview).addnewnode (SubString(s,c,StrLength(s)-c))
		End If
		node2.ImageIndex = 2
		node2.SelectedImageIndex = 2
	Next
	If ControlType(node) = "TreeView.Node" Then
		Control(node,node).expandall
	Else
		Control(node,treeview).expandall
	End If
	WaitCursor(false)
End Sub
Reply With Quote
  #13 (permalink)  
Old 03-21-2008, 12:13 PM
specci48's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: Germany
Posts: 650
Default

Quote:
Originally Posted by agraham View Post
You need a conditional test to find out which.
... exactly what I said: you have to code twice ...
Reply With Quote
  #14 (permalink)  
Old 03-21-2008, 04:33 PM
Basic4ppc Veteran
 
Join Date: Feb 2008
Location: Hilversum, The Netherlands
Posts: 208
Awards Showcase
Beta Tester 
Total Awards: 1
Default

@ specci48
I tried changing the compiler like you mentioned, and I got it working ( the original file)
So I incorporated that in my program and it worked! the only drawback is that the (or a) sub "remembers" the last folder opened and if used again it will not read the new folder that is clicked, so i cannot re-use the code to open another file, I think it probably has to do with the naming issue agraham found. I already tried to set most of the variables to "" but that didn't work...so thats next on my list :-)

@agraham
great job, I'll try your version next, the compiled file is pretty big compared to the optimized version

@RandomCoder
Sure i'll try anything to get it working, I'm actually losing sleep over this ;-)

Last night I thought of making a standalone version of the folderchooser program, this could then write the location to an temp file and my program could then read it when it gets focus...

Thank you all for your help on this, I'll let you know if it works
Reply With Quote
  #15 (permalink)  
Old 03-21-2008, 05:37 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,199
Default

I've updated the extended FolderChooser example to support the optimized compiler:
http://www.basic4ppc.com/forum/showthread.php?p=2871
Reply With Quote
  #16 (permalink)  
Old 03-21-2008, 07:13 PM
Basic4ppc Veteran
 
Join Date: Feb 2008
Location: Hilversum, The Netherlands
Posts: 208
Awards Showcase
Beta Tester 
Total Awards: 1
Default

thanks Erel
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Specified cast is not valid bish0p Questions & Help Needed 1 07-11-2008 08:17 PM
identifying a node in treeview BjornF Questions & Help Needed 3 05-29-2008 05:47 PM
Specified cast is not valid skipper Questions & Help Needed 7 03-12-2008 08:17 AM
Object Reference not set to an instance of an object monster9999 Questions & Help Needed 9 01-15-2008 10:56 PM
treeview color (node) tvrman Questions & Help Needed 2 08-04-2007 06:57 PM


All times are GMT. The time now is 01:56 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0