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
160
Ultragrid Hierarchical DataSource with Multiple Level Paths
posted

I have a class

 

    public class MyObject {

        public string Caption { get; set; }

        public string SomeText { get; set; }

        public IList<MyObject> ChildItems { get; set; }

        public Dictionary<string,Action> ItemActions { get; set; }

    }

 

and an UltraGrid whose DataSource will be an IList<MyObject>.

 

    IList<MyObject> list = ListRepository.GetAll<MyObject>();

    MyUltraGrid.DataSource = list.

 

When I set an IList<MyObject> as the UltraGrid's DataSource it seems that the Dictionary property ItemActions is being chosen as the property to use to create bands in the grid and I get Key Not Found exceptions when trying to access columns in lower bands, because I'm expecting the columns in lower bands to be keyed of of other properties of MyObject.

For example:

    MyGrid.DisplayLayout.Bands[1].Columns["SomeText"].PerformAutoResize();

would result in an exception because the "SomeText" key of the Columns collection doesn't exist.  Band[1] gets created from the Dictionary property of MyObject instead of the IList<MyObject> property.

I have worked around this for now by changing the ItemActions property to type Object instead of a Dictionary and casting when I need to reference it, but I'd rather not have to do that.

Is there a way to force the UltraGrid binding to choose ChildItems as the hierarchy path?

Parents
  • 469350
    Offline posted

    Hi,

    It's probably because you are using IList<T>. Using an interface instead of a concrete implementation will cause all sorts of problems when binding.Also, IList is not a great interface to use for DataBinding, anyway. It's very limited and won't support all of the notifications needed for DataBinding.

    Change IList<T> to List<T> or better yet, BindingList<T> and it will work a lot better.

     

Reply Children