Connecting Tech Pros Worldwide Help | Site Map

Attribute problem

Newbie
 
Join Date: Apr 2009
Posts: 11
#1: Jun 2 '09
Hi there
How can i solve this problem??

P Property is here...
Expand|Select|Wrap|Line Numbers
  1.     public partial class combo : ComboBox
  2.     {
  3.         public combo()
  4.         {
  5.             InitializeComponent();
  6.         }
  7.  
  8.         private MyClass p = new MyClass(2, 4);
  9.         public MyClass P
  10.         {
  11.             get { return p; }
  12.             set { p = value; }
  13.         }
  14.     }
  15.  
and MyClass class is here....
Expand|Select|Wrap|Line Numbers
  1.     [TypeConverter(typeof(ExpandableObjectConverter))]
  2.     public class MyClass
  3.     {
  4.         private int _width, _hieght;
  5.         public MyClass()
  6.         {
  7.         }
  8.         public MyClass(int width, int height)
  9.         {
  10.             _width = width;
  11.             _hieght = height;
  12.         }
  13.  
  14.         public int Width
  15.         {
  16.             get { return _width; }
  17.             set { _width = value; }
  18.         }
  19.         public int Height
  20.         {
  21.             get { return _hieght; }
  22.             set { _hieght = value; }
  23.         }
  24.     }
  25.  
Attached Thumbnails
sa.jpg  
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#2: Jun 2 '09

re: Attribute problem


What is the problem?
Expert
 
Join Date: Jan 2008
Location: York
Posts: 179
#3: Jun 2 '09

re: Attribute problem


At a guess you don't want the property to read "test_1.MyClass"?

If this is the case override the ToString() method on MyClass and return a more appropriate value.
Newbie
 
Join Date: Apr 2009
Posts: 11
#4: Jun 2 '09

re: Attribute problem


thanks.i override the ToString() method but it is readonly now.
for example size property is changeable but my property is not.(problem is attached....)
Attached Thumbnails
untitled.jpg  
Newbie
 
Join Date: Apr 2009
Posts: 11
#5: Jun 2 '09

re: Attribute problem


it's ok.i find its solution.
very very thanks.....
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,752
#6: Jun 2 '09

re: Attribute problem


Quote:

Originally Posted by IanWright View Post

At a guess you don't want the property to read "test_1.MyClass"?

If this is the case override the ToString() method on MyClass and return a more appropriate value.

I cheat and use the System.IO.Path.GetNameWithoutExtension for things like this.
Feed it "test_1.MyClass" and it trims the 'extension of .MyClass
Newbie
 
Join Date: Apr 2009
Posts: 11
#7: Jun 2 '09

re: Attribute problem


i don't understand ur meaning.what's profit of cheating in this case?
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,752
#8: Jun 2 '09

re: Attribute problem


The 'right' way really is to override the ToString() method and so forth.
But I'm lazy sometimes. Event though the string isn't a Path, the System.IO.Path functions are written well enough to not scream about it and so I can use them to do my evil bidding <mad scientist laugh>
Reply