Click here to Skip to main content
15,907,329 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to define a function from WIN32 DLL in c# . Pin
dfbx6-Jun-06 19:21
dfbx6-Jun-06 19:21 
QuestionDisplay of text delayed [modified] Pin
printscreen123456-Jun-06 15:53
printscreen123456-Jun-06 15:53 
AnswerRe: Display of text delayed [modified] Pin
Guffa6-Jun-06 19:00
Guffa6-Jun-06 19:00 
GeneralRe: Display of text delayed [modified] Pin
printscreen123456-Jun-06 19:33
printscreen123456-Jun-06 19:33 
AnswerRe: Display of text delayed [modified] Pin
Guffa6-Jun-06 23:15
Guffa6-Jun-06 23:15 
GeneralRe: Display of text delayed [modified] Pin
printscreen123457-Jun-06 1:37
printscreen123457-Jun-06 1:37 
GeneralRe: Display of text delayed [modified] Pin
Guffa7-Jun-06 20:23
Guffa7-Jun-06 20:23 
GeneralRe: Display of text delayed Pin
printscreen123459-Jun-06 21:30
printscreen123459-Jun-06 21:30 
AnswerRe: Display of text delayed Pin
Guffa9-Jun-06 22:22
Guffa9-Jun-06 22:22 
GeneralRe: Display of text delayed Pin
printscreen1234510-Jun-06 1:23
printscreen1234510-Jun-06 1:23 
QuestionData binding Pin
liquid_6-Jun-06 11:28
liquid_6-Jun-06 11:28 
QuestionDatagridview and checkbox column Pin
perryf006-Jun-06 10:48
perryf006-Jun-06 10:48 
AnswerRe: Datagridview and checkbox column Pin
Mairaaj Khan6-Jun-06 22:15
professionalMairaaj Khan6-Jun-06 22:15 
QuestionColumn Width Pin
gregbushman6-Jun-06 8:18
gregbushman6-Jun-06 8:18 
GeneralRe: Column Width Pin
Guffa6-Jun-06 8:44
Guffa6-Jun-06 8:44 
AnswerRe: Column Width Pin
yodern6-Jun-06 23:32
yodern6-Jun-06 23:32 
QuestionNeed help in messenger Pin
Musharaf Zaheer6-Jun-06 7:50
Musharaf Zaheer6-Jun-06 7:50 
GeneralRe: Need help in messenger Pin
Guffa6-Jun-06 11:15
Guffa6-Jun-06 11:15 
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 
I have a class I am calling SimTreeNode which is a System.Windows.Forms.TreeNode type. I am planning on using this class within my TreeView class.

Class Definition:

using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
<br />
namespace SimTree<br />
{<br />
    public class SimTreeNode : System.Windows.Forms.TreeNode<br />
    {<br />
        //public static explicit operator SimTreeNode(TreeNode tn)<br />
        //{<br />
<br />
        //}<br />
    }<br />
}


As you can see, I don't do anything more or less than the TreeNode class.

The problem is, when I try to use my SimTreeNode in place of any TreeNode in my TreeView class, it throws runtime errors.

Here is the snippet of code I am doing the conversion.

using System.Collections;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Drawing;<br />
using System.Data;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
using System.Xml;<br />
using System.Xml.Serialization;<br />
using SimTree.Properties;<br />
using System.Runtime.InteropServices;<br />
<br />
namespace SimTree<br />
{<br />
    public partial class SimTree : System.Windows.Forms.TreeView<br />
    {<br />
<br />
          private void SimTree_ItemDrag(object sender, ItemDragEventArgs e)<br />
          {<br />
              // Do not allow anything other than devices to be dragged<br />
              Point pt = this.PointToClient(Control.MousePosition);<br />
              SimTreeNode tn = (SimTreeNode)this.GetNodeAt(pt); // <--- Runtime error here<br />
<br />
              ...<br />
          }<br />
   }<br />
}


Runtime Error:

Unable to cast object of type 'System.Windows.Forms.TreeNode' to type 'SimTree.SimTreeNode'.

I would like to know why I cant caste my derived type to my base type.

According to a million online forums, I don't need to make an explicit operator to caste to/from base types. I actually tried to make an explicit caste operator if you look at my comments in the SimTree.SimTreeNode class, but gave me a compiler error:

Error 1 'SimTree.SimTreeNode.explicit operator SimTree.SimTreeNode(System.Windows.Forms.TreeNode)': user-defined conversion to/from base class C:\...\SimTree\SimTreeNode.cs 10 23 SimTree

This really doesn't make any sense to me as the compiler SHOULDN'T have anyway of telling how to convert a base type to a derived type without me telling it explicitly.

I am hitting brick walls left and right with this simple thing I want to do. Mad | :mad:
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 

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.