Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1170
Binding a composite object to UltraWingrid
posted

Hi,

I have a class like the following 

class MyCompositeClass
    {
        private string property1 = "prop1";
 
        [DisplayName("Identifier")]
        public string Property1
        {
            get { return property1; }
            set { property1 = value; }
        }
        private string property2 = "Prop2";
 
        public string Property2
        {
            get { return property2; }
            set { property2 = value; }
        }
        private MyInnerClass innerClassObj = new MyInnerClass();
 
        public MyInnerClass InnerClassObj
        {
            get { return innerClassObj; }
            set { innerClassObj = value; }
        }
    }

class MyInnerClass
    {
        public MyInnerClass()
        {
            mystring = "sadf";
        }
 
        private string mystring = null;
 
        public string Mystring
        {
            get { return mystring; }
            set { mystring = value; }
        }
 
    }

i am binding a list of MyCompositeClass to the ultragrid like following

BindingList<MyCompositeClass> comp = new BindingList<MyCompositeClass> { new MyCompositeClass() ,new MyCompositeClass()};
            ultraGrid1.DataSource = comp;

Can I show the public properties of MyInnerClass in the same band as the MyCompositeClass in some straightforward way?

Parents
No Data
Reply
  • 469350
    Offline posted

    There are a number of approaches you can take here.

    Do you need the MyString field to be editable?

    Is there really only one string property on MyInnerClass, or is that just an example?

    If you have only a single property to display and it doesn't require editing, then this is very simple. All you have to do is override ToString on MyInnerClass and return MyString. the grid will show the ToString method of the property value.

    If you need the string to be editable, it's a little more complex. You could achieve that using a DataFilter.

    If there is more than one property on MyInnerClass, then you could add an unbound column to the grid for each one and then use the InitializeRow event to populate the unbound columns with the data from MyInnerClass on each row. You would also have to handle BeforeRowUpdate to write any edits to the underlying object if the data is editable.

Children