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

C#

 
QuestionC# Class Inheritance Pin
LighthouseJ2-Feb-06 11:16
LighthouseJ2-Feb-06 11:16 
AnswerRe: C# Class Inheritance Pin
Guffa2-Feb-06 11:21
Guffa2-Feb-06 11:21 
GeneralRe: C# Class Inheritance Pin
LighthouseJ2-Feb-06 11:44
LighthouseJ2-Feb-06 11:44 
AnswerRe: C# Class Inheritance Pin
Guffa2-Feb-06 22:19
Guffa2-Feb-06 22:19 
GeneralRe: C# Class Inheritance Pin
LighthouseJ3-Feb-06 4:34
LighthouseJ3-Feb-06 4:34 
AnswerRe: C# Class Inheritance Pin
Ravi Bhavnani2-Feb-06 11:24
professionalRavi Bhavnani2-Feb-06 11:24 
GeneralRe: C# Class Inheritance Pin
LighthouseJ2-Feb-06 11:45
LighthouseJ2-Feb-06 11:45 
AnswerRe: C# Class Inheritance Pin
malharone2-Feb-06 11:37
malharone2-Feb-06 11:37 
LighthouseJ wrote:
The project is too complex


Here's a simple solution.. has the same class hierarchy as you described.. and it shows the .ToString() values. (I hope you're not confusing ListBox with ListView)

- Malhar

using System;<br />
using System.Drawing;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Windows.Forms;<br />
<br />
namespace Malhar.ControlGallery<br />
{<br />
	/// <summary><br />
	/// Summary description for Form3.<br />
	/// </summary><br />
	public class Form3 : System.Windows.Forms.Form<br />
	{<br />
		private System.Windows.Forms.ListBox listBox1;<br />
		private System.Windows.Forms.Button Load;<br />
		/// <summary><br />
		/// Required designer variable.<br />
		/// </summary><br />
		private System.ComponentModel.Container components = null;<br />
<br />
		public Form3()<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 />
<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.listBox1 = new System.Windows.Forms.ListBox();<br />
			this.Load = new System.Windows.Forms.Button();<br />
			this.SuspendLayout();<br />
			// <br />
			// listBox1<br />
			// <br />
			this.listBox1.Location = new System.Drawing.Point(8, 16);<br />
			this.listBox1.Name = "listBox1";<br />
			this.listBox1.Size = new System.Drawing.Size(176, 95);<br />
			this.listBox1.TabIndex = 0;<br />
			// <br />
			// Load<br />
			// <br />
			this.Load.Location = new System.Drawing.Point(192, 8);<br />
			this.Load.Name = "Load";<br />
			this.Load.TabIndex = 1;<br />
			this.Load.Text = "button1";<br />
			this.Load.Click += new System.EventHandler(this.button1_Click);<br />
			// <br />
			// Form3<br />
			// <br />
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);<br />
			this.ClientSize = new System.Drawing.Size(292, 266);<br />
			this.Controls.Add(this.Load);<br />
			this.Controls.Add(this.listBox1);<br />
			this.Name = "Form3";<br />
			this.Text = "Form3";<br />
			this.ResumeLayout(false);<br />
<br />
		}<br />
		#endregion<br />
<br />
		private void button1_Click(object sender, System.EventArgs e)<br />
		{<br />
			listBox1.Items.Add(new A());<br />
			listBox1.Items.Add(new B());<br />
			listBox1.Items.Add(new C("John", 4));<br />
			listBox1.Items.Add(new C("Lisa", 10));<br />
			listBox1.Items.Add(new D());<br />
		}<br />
<br />
		class A<br />
		{<br />
			public A():base()<br />
			{<br />
			}<br />
			public override string ToString()<br />
			{<br />
				return "Object of type A";<br />
			}<br />
		}<br />
		class B:ArrayList<br />
		{<br />
			public B():base()<br />
			{<br />
			}<br />
			public override string ToString()<br />
			{<br />
				return "Object of type B";<br />
			}<br />
		}<br />
		class C:B<br />
		{<br />
			string someStr;<br />
			object someVal;<br />
			public C(string text, object value)<br />
			{<br />
				someStr = text;<br />
				someVal = value;<br />
			}<br />
			public override string ToString()<br />
			{<br />
				return string.Format("Object of type C: {0}; {1}", (someStr==null?"-":someStr), (someVal==null?"-":someVal.ToString()));<br />
			}<br />
		}<br />
		class D:B<br />
		{<br />
			public D()<br />
			{<br />
			}<br />
			public override string ToString()<br />
			{<br />
				return "Object of type D";<br />
			}<br />
		}<br />
	}<br />
}

GeneralRe: C# Class Inheritance Pin
LighthouseJ2-Feb-06 11:53
LighthouseJ2-Feb-06 11:53 
QuestionEDIT MENU + CUT, COPY, PASTE Pin
emran8342-Feb-06 11:08
emran8342-Feb-06 11:08 
AnswerRe: EDIT MENU + CUT, COPY, PASTE Pin
J4amieC2-Feb-06 23:08
J4amieC2-Feb-06 23:08 
GeneralRe: EDIT MENU + CUT, COPY, PASTE Pin
emran8343-Feb-06 17:20
emran8343-Feb-06 17:20 
QuestionGet a controll fully customized Pin
Sasuko2-Feb-06 10:22
Sasuko2-Feb-06 10:22 
AnswerRe: Get a controll fully customized Pin
Ingo3-Feb-06 2:14
Ingo3-Feb-06 2:14 
QuestionTo know which file was opened by an application. Pin
yjoo93172-Feb-06 10:13
yjoo93172-Feb-06 10:13 
AnswerRe: To know which file was opened by an application. Pin
malharone2-Feb-06 11:11
malharone2-Feb-06 11:11 
GeneralRe: To know which file was opened by an application. Pin
yjoo93172-Feb-06 11:26
yjoo93172-Feb-06 11:26 
GeneralRe: To know which file was opened by an application. Pin
Dave Kreskowiak2-Feb-06 15:40
mveDave Kreskowiak2-Feb-06 15:40 
QuestionValidation of WinForm Data Pin
Wayne Phipps2-Feb-06 9:51
Wayne Phipps2-Feb-06 9:51 
QuestionPixel size of frame and control changed Pin
xjsun2-Feb-06 9:35
xjsun2-Feb-06 9:35 
AnswerRe: Pixel size of frame and control changed Pin
malharone2-Feb-06 11:15
malharone2-Feb-06 11:15 
GeneralRe: Pixel size of frame and control changed Pin
xjsun7-Feb-06 8:09
xjsun7-Feb-06 8:09 
GeneralRe: Pixel size of frame and control changed Pin
malharone7-Feb-06 8:11
malharone7-Feb-06 8:11 
Questionthread safe calls Pin
Manu_812-Feb-06 8:37
Manu_812-Feb-06 8:37 
AnswerRe: thread safe calls Pin
kasik2-Feb-06 9:35
kasik2-Feb-06 9:35 

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.