Click here to Skip to main content
15,891,184 members
Home / Discussions / C#
   

C#

 
QuestionCheck the internet connection status Pin
ventomito6-Jun-06 7:31
ventomito6-Jun-06 7:31 
AnswerRe: Check the internet connection status Pin
Paul Brower6-Jun-06 10:38
Paul Brower6-Jun-06 10:38 
GeneralRe: Check the internet connection status Pin
ventomito7-Jun-06 2:21
ventomito7-Jun-06 2:21 
QuestionCasting from derived class to base class Pin
Melon006-Jun-06 7:02
Melon006-Jun-06 7:02 
AnswerRe: Casting from derived class to base class Pin
Wjousts6-Jun-06 7:13
Wjousts6-Jun-06 7:13 
AnswerRe: Casting from derived class to base class Pin
Josh Smith6-Jun-06 9:28
Josh Smith6-Jun-06 9:28 
AnswerRe: Casting from derived class to base class Pin
Guffa6-Jun-06 11:24
Guffa6-Jun-06 11:24 
AnswerRe: Casting from derived class to base class Pin
Ret Orrick6-Jun-06 15:49
Ret Orrick6-Jun-06 15:49 
Just been through this myself. Life would have been so much easier if the Treeview had a free property of type Object then we could have easily added a helper class with additional properties and methods. Anyway, back to your problem. I suspect you added your SimTreeNode as a TreeNode. You can only cast in one direction. You can cast SimTreeNode stored in a Treenode variable to a SimNode, But you cannot cast a TreeNode stored in a TreeNode variable to SimNode.

You used the word converting. That's not really appropriate as the objects are not converted. All it is doing is copying pointer. We know that the derived class has all the facilities of the parent class so casting from SimtreeNode to TreeNode is safe. If the compiler let you go the other way we would end up with:

TreeNode tn = new TreeNode()
SimtreeNode stn = (SimTreeNode)tn
stn.SomeMethodThatDoesNotExistinTreeNode()

So the compiler does not allow it.

Take a look in debug just as you execute the statement and make sure that you do objects of the type you needed. Overriding ToString is always useful when you extend TreeViews.

To ensure you are safe override in SimTreeView the Add method for a treenode and make it private. Then add your own Add method for SimTreeNode

Paul
QuestionPlease Help ! Pin
mostafa_h6-Jun-06 4:25
mostafa_h6-Jun-06 4:25 
AnswerRe: Please Help ! Pin
CodyGen6-Jun-06 5:45
CodyGen6-Jun-06 5:45 
GeneralRe: Please Help ! Pin
mostafa_h6-Jun-06 11:25
mostafa_h6-Jun-06 11:25 
Questionquestion about time and date format ? [modified] Pin
cmpeng346-Jun-06 4:20
cmpeng346-Jun-06 4:20 
AnswerRe: question about time and date format ? Pin
Dustin Metzgar6-Jun-06 4:39
Dustin Metzgar6-Jun-06 4:39 
AnswerRe: question about time and date format ? [modified] Pin
Wjousts6-Jun-06 4:40
Wjousts6-Jun-06 4:40 
QuestionDirect instantiation of Bitmap from unsafe memory Pin
Florian Storck6-Jun-06 4:10
Florian Storck6-Jun-06 4:10 
QuestionGet file that spawned the application. Pin
cmarcus6-Jun-06 4:01
cmarcus6-Jun-06 4:01 
AnswerRe: Get file that spawned the application. Pin
Stephan Samuel6-Jun-06 4:08
Stephan Samuel6-Jun-06 4:08 
GeneralRe: Get file that spawned the application. Pin
cmarcus6-Jun-06 5:58
cmarcus6-Jun-06 5:58 
AnswerRe: Get file that spawned the application. Pin
J4amieC6-Jun-06 4:11
J4amieC6-Jun-06 4:11 
AnswerRe: Get file that spawned the application - New Problem Pin
cmarcus6-Jun-06 8:44
cmarcus6-Jun-06 8:44 
QuestionShared Add-in for Excel 2003 and Garbage Collector Pin
Kadur6-Jun-06 3:55
Kadur6-Jun-06 3:55 
QuestionObject lifetime, GC and the State Pattern [modified] Pin
User 66586-Jun-06 3:54
User 66586-Jun-06 3:54 
AnswerRe: Object lifetime, GC and the State Pattern [modified] Pin
Stephan Samuel6-Jun-06 4:03
Stephan Samuel6-Jun-06 4:03 
GeneralRe: Object lifetime, GC and the State Pattern [modified] Pin
User 66586-Jun-06 4:07
User 66586-Jun-06 4:07 
GeneralRe: Object lifetime, GC and the State Pattern Pin
Stephan Samuel6-Jun-06 6:53
Stephan Samuel6-Jun-06 6:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.