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.
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,
This will not work because I don't know all the fields of base class (Person class in your example) until run time. The UI behavior is more like excel where you can keep adding columns on per need basis. I can not keep adding unbound columns to the grid because eventually I have to persist this structure in a database. I added an observeablecollection<string> to accomodate this requirement. I was using my object model to bind against wpf DataGrid from Microsoft (part of their toolkit) and it was rendering correctly. But when I switched to XamGrid it started treating it as child object.