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
470
Databinding on Grid
posted

Hi,

my grid displays a list of customer-objects. one column displays the adress (it is bound to the Adress - property of the customer).

The DataSource of the grid is a BindingSource witch contains customer objects.

 

The Objects are:

     public class Adress

    {

        public string Street {get; set}

        public string City {get; set} 

 

        public override string ToString()

        {

            return string.Format("{0} - {1}", Name, City);

        }

    } 

    public class Customer

    {

        public string Name {get; set}

        public Adress Adress {get; set} 

    }

 

How can I configure the column "Adress" in the customer grid, that the following goals are reached?

  • the column should display the city of the adress object
  • the column should have an editor (the open a dropdown editor) to select a new adress for current the customer-object

 

I hope someone can help me!

Michael 

 

Parents
No Data
Reply
  • 469350
    Verified Answer
    Offline posted

    Hi Michael,

    The grid will display the ToString method of the object. So one way you could get this to work would be to overide the ToString method on the your Address class and return a meaningful string. By default, ToString returns the type name, which is probably not very useful to your users. 

    Regarding an editor, it depends what you want. If you just want a dropdown list of addresses, then this KB article should help you: HOWTO:What is the best way to place a DropDown list in a grid cell?

    If you want something more complex where the user can type in an address, then you would probably need to create your own address editor of some kind and create your own dropdown. This is a lot easier than it might sound, since you can use an UltraTextEditor control and add a DropDownEditorButton to it and put a UserControl or whatever you want into the dropdown. 

Children