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
265
Excel Style Adding Rows/Columns dynamically
posted

I am working on a project to use XamGrid to create an interface that will behave like an excel worksheet in many way. User should be able to add, remove, rearrange columns at run time and persist the resultant grid structure to a database. I am binding this grid to an ObserveableCollection<TemplateRow> where

public class TemplateRow { public ObservableCollection<string> Cells { get; set;} }

Logically this object seems ok but XamGrid renders it as hierarchical and I can see why it's doing that. Any ideas on how my Grid bindings or object structure should look like to accomplish this.

 

 

Parents
No Data
Reply
  • 28464
    posted

    Hello,

    xamDataGrid can bind to any object, but while doing so it searches for child collections inside the object, like IList collections, ObservableCollections, CollectionViews, etc. At this point the grid assumes that this inner collection is a child collection and creates a hirarchy based on that.

    So I guess what you need to do is just to create a base class that has all columns (fields) defined as properties, and then create an ObservableCollection based on that.

    e.g.

    public class Person

    {

         string FirstName {get;set; }

         string LastName {get;set; }

    }

    then create ObservableCollection < Person >

    and finallly bind this ObservableCollection to the grid.

    HTH,

Children