Click here to Skip to main content
15,389,911 members
Home / Discussions / C#
   

C#

 
GeneralRe: Crystal Reports and Sql Server 2000 Pin
obelisk298-Jan-04 13:01
Memberobelisk298-Jan-04 13:01 
GeneralRe: Crystal Reports and Sql Server 2000 Pin
Heath Stewart8-Jan-04 13:11
protectorHeath Stewart8-Jan-04 13:11 
GeneralRe: Crystal Reports and Sql Server 2000 Pin
obelisk298-Jan-04 13:20
Memberobelisk298-Jan-04 13:20 
GeneralRe: Crystal Reports and Sql Server 2000 Pin
obelisk298-Jan-04 14:10
Memberobelisk298-Jan-04 14:10 
GeneralRe: Crystal Reports and Sql Server 2000 Pin
obelisk298-Jan-04 14:30
Memberobelisk298-Jan-04 14:30 
GeneralDynamic Casting for use in Polymorphic/overloaded methods. Pin
Scott Barr8-Jan-04 11:12
MemberScott Barr8-Jan-04 11:12 
GeneralRe: Dynamic Casting for use in Polymorphic/overloaded methods. Pin
Heath Stewart8-Jan-04 11:50
protectorHeath Stewart8-Jan-04 11:50 
GeneralRe: Dynamic Casting for use in Polymorphic/overloaded methods. Pin
Scott Barr9-Jan-04 4:42
MemberScott Barr9-Jan-04 4:42 
You are correct, but in terms of a treeview and or any of the event driven systems not quite.
Take a look at the following event handler
<br />
 private void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)<br />
        {<br />
            this.DisplayType( e.Node );        <br />
        }<br />


You are passed the node from e (e.Node) and it is of type TreeNode. If you call e.Node.GetType() you will get the correct type but when used in the following context it is simply a TreeNode the base class. See method DisplayType() methods and the treeView1_AfterSelect() method.

Copy/Paste and run the following example and you will see what I mean.

<br />
using System;<br />
using System.Drawing;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Windows.Forms;<br />
using System.Data;<br />
<br />
namespace test<br />
{<br />
	/// <summary><br />
	/// Summary description for Form1.<br />
	/// </summary><br />
	public class Form1 : System.Windows.Forms.Form<br />
	{<br />
        private System.Windows.Forms.TreeView treeView1;<br />
		/// <summary><br />
		/// Required designer variable.<br />
		/// </summary><br />
		private System.ComponentModel.Container components = null;<br />
<br />
		public Form1()<br />
		{<br />
			//<br />
			// Required for Windows Form Designer support<br />
			//<br />
			InitializeComponent();<br />
<br />
			//<br />
			// TODO: Add any constructor code after InitializeComponent call<br />
			//<br />
<br />
            TreeNodeType1 tnt1 = new TreeNodeType1();<br />
            tnt1.Text = "Type 1";<br />
<br />
            TreeNodeType2 tnt2 = new TreeNodeType2();<br />
            tnt2.Text = "Type 2";<br />
<br />
            this.treeView1.Nodes[0].Nodes.Add( tnt1 );<br />
            this.treeView1.Nodes[0].Nodes.Add( tnt2 );<br />
<br />
		}<br />
<br />
		/// <summary><br />
		/// Clean up any resources being used.<br />
		/// </summary><br />
		protected override void Dispose( bool disposing )<br />
		{<br />
			if( disposing )<br />
			{<br />
				if (components != null) <br />
				{<br />
					components.Dispose();<br />
				}<br />
			}<br />
			base.Dispose( disposing );<br />
		}<br />
<br />
		#region Windows Form Designer generated code<br />
		/// <summary><br />
		/// Required method for Designer support - do not modify<br />
		/// the contents of this method with the code editor.<br />
		/// </summary><br />
		private void InitializeComponent()<br />
		{<br />
            this.treeView1 = new System.Windows.Forms.TreeView();<br />
            this.SuspendLayout();<br />
            // <br />
            // treeView1<br />
            // <br />
            this.treeView1.Dock = System.Windows.Forms.DockStyle.Fill;<br />
            this.treeView1.ImageIndex = -1;<br />
            this.treeView1.Location = new System.Drawing.Point(0, 0);<br />
            this.treeView1.Name = "treeView1";<br />
            this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {<br />
                                                                                  new System.Windows.Forms.TreeNode("Root Node")});<br />
            this.treeView1.SelectedImageIndex = -1;<br />
            this.treeView1.Size = new System.Drawing.Size(412, 393);<br />
            this.treeView1.TabIndex = 0;<br />
            this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect);<br />
            // <br />
            // Form1<br />
            // <br />
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);<br />
            this.ClientSize = new System.Drawing.Size(412, 393);<br />
            this.Controls.Add(this.treeView1);<br />
            this.Name = "Form1";<br />
            this.Text = "Form1";<br />
            this.ResumeLayout(false);<br />
<br />
        }<br />
		#endregion<br />
<br />
		/// <summary><br />
		/// The main entry point for the application.<br />
		/// </summary><br />
		[STAThread]<br />
		static void Main() <br />
		{<br />
			Application.Run(new Form1());<br />
		}<br />
<br />
        private void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)<br />
        {<br />
            this.DisplayType( e.Node );        <br />
        }<br />
<br />
        private void DisplayType( object inNode )<br />
        {<br />
          MessageBox.Show(<br />
                    "Caught an Object",<br />
                    "Name Entry Error",<br />
                    MessageBoxButtons.OK,<br />
                    MessageBoxIcon.Exclamation );<br />
        }<br />
<br />
        private void DisplayType( TreeNodeType1 inNode )<br />
        {<br />
            MessageBox.Show(<br />
                    "Caught a TreeNode1",<br />
                    "Name Entry Error",<br />
                    MessageBoxButtons.OK,<br />
                    MessageBoxIcon.Exclamation );<br />
        }<br />
<br />
        private void DisplayType( TreeNodeType2 inNode )<br />
        {<br />
            MessageBox.Show(<br />
                    "Caught a TreeNode2",<br />
                    "Name Entry Error",<br />
                    MessageBoxButtons.OK,<br />
                    MessageBoxIcon.Exclamation );<br />
        }<br />
	}<br />
    <br />
    public class TreeNodeType1 : System.Windows.Forms.TreeNode<br />
    {<br />
        public TreeNodeType1()<br />
        {<br />
            //<br />
            // TODO: Add constructor logic here<br />
            //<br />
        }<br />
    }<br />
<br />
    public class TreeNodeType2 : System.Windows.Forms.TreeNode<br />
    {<br />
        public TreeNodeType2()<br />
        {<br />
            //<br />
            // TODO: Add constructor logic here<br />
            //<br />
        }<br />
    }<br />
}<br />
<br />


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Scott Barr
Senior Software Engineer
scott@thorin.ca
http://www.thorin.ca
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
GeneralRe: Dynamic Casting for use in Polymorphic/overloaded methods. Pin
Heath Stewart9-Jan-04 5:15
protectorHeath Stewart9-Jan-04 5:15 
GeneralRe: Dynamic Casting for use in Polymorphic/overloaded methods. Pin
Scott Barr9-Jan-04 5:30
MemberScott Barr9-Jan-04 5:30 
GeneralType convertion and Unmanaged code Pin
Shahin778-Jan-04 10:48
MemberShahin778-Jan-04 10:48 
GeneralRe: Type convertion and Unmanaged code Pin
Heath Stewart8-Jan-04 11:39
protectorHeath Stewart8-Jan-04 11:39 
GeneralRe: Type convertion and Unmanaged code Pin
Shahin778-Jan-04 11:52
MemberShahin778-Jan-04 11:52 
GeneralRe: Type convertion and Unmanaged code Pin
Heath Stewart8-Jan-04 12:16
protectorHeath Stewart8-Jan-04 12:16 
GeneralRe: Type convertion and Unmanaged code Pin
Heath Stewart8-Jan-04 12:37
protectorHeath Stewart8-Jan-04 12:37 
GeneralRe: Type convertion and Unmanaged code Pin
Shahin778-Jan-04 14:15
MemberShahin778-Jan-04 14:15 
GeneralStartup Switch Options ... Pin
Daniel Negron8-Jan-04 10:08
MemberDaniel Negron8-Jan-04 10:08 
GeneralRe: Startup Switch Options ... Pin
Niels Penneman8-Jan-04 10:43
MemberNiels Penneman8-Jan-04 10:43 
GeneralRe: Startup Switch Options ... Pin
Heath Stewart8-Jan-04 11:34
protectorHeath Stewart8-Jan-04 11:34 
GeneralWriting CD/DVD Pin
Christian Graus8-Jan-04 9:37
mveChristian Graus8-Jan-04 9:37 
GeneralRe: Writing CD/DVD Pin
Mazdak8-Jan-04 9:55
MemberMazdak8-Jan-04 9:55 
GeneralRe: Writing CD/DVD Pin
Christian Graus8-Jan-04 9:59
mveChristian Graus8-Jan-04 9:59 
GeneralRe: Writing CD/DVD Pin
Kentamanos8-Jan-04 10:25
MemberKentamanos8-Jan-04 10:25 
GeneralRe: Writing CD/DVD Pin
Kentamanos8-Jan-04 16:51
MemberKentamanos8-Jan-04 16:51 
GeneralRe: Writing CD/DVD Pin
Christian Graus8-Jan-04 17:08
mveChristian Graus8-Jan-04 17:08 

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.