Attribute problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sajjadlove
    New Member
    • Apr 2009
    • 19

    Attribute problem

    Hi there
    How can i solve this problem??

    P Property is here...
    Code:
        public partial class combo : ComboBox
        {
            public combo()
            {
                InitializeComponent();
            }
    
            private MyClass p = new MyClass(2, 4);
            public MyClass P
            {
                get { return p; }
                set { p = value; }
            }
        }
    and MyClass class is here....
    Code:
        [TypeConverter(typeof(ExpandableObjectConverter))]
        public class MyClass
        {
            private int _width, _hieght;
            public MyClass()
            {
            }
            public MyClass(int width, int height)
            {
                _width = width;
                _hieght = height;
            }
    
            public int Width
            {
                get { return _width; }
                set { _width = value; }
            }
            public int Height
            {
                get { return _hieght; }
                set { _hieght = value; }
            }
        }
    Attached Files
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    What is the problem?

    Comment

    • IanWright
      New Member
      • Jan 2008
      • 179

      #3
      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.

      Comment

      • sajjadlove
        New Member
        • Apr 2009
        • 19

        #4
        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 Files

        Comment

        • sajjadlove
          New Member
          • Apr 2009
          • 19

          #5
          it's ok.i find its solution.
          very very thanks.....

          Comment

          • tlhintoq
            Recognized Expert Specialist
            • Mar 2008
            • 3532

            #6
            Originally posted by IanWright
            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. GetNameWithoutE xtension for things like this.
            Feed it "test_1.MyClass " and it trims the 'extension of .MyClass

            Comment

            • sajjadlove
              New Member
              • Apr 2009
              • 19

              #7
              i don't understand ur meaning.what's profit of cheating in this case?

              Comment

              • tlhintoq
                Recognized Expert Specialist
                • Mar 2008
                • 3532

                #8
                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>

                Comment

                Working...