Hi,
I am trying to generated GroupColumns dynamically, so would like to know if there is any way that I can bind a list or something to GroupColumns, so that n number of group columns can be created on the fly.
A sample would be highly appreciated. FYI - I would like to achieve this thing only through xaml and no code behind.
Thanks,
Sunil
Hello Sunil,
Thank you for your post. I have been looking into it and I can say that since the XamGrid’s GrouBySettings’ GroupedColumns Collection is read only and cannot be set, you are only allowed to add items to it. Here it is explained how to group columns via code:
http://help.infragistics.com/NetAdvantage/WPF/2012.1/CLR4.0/?page=xamGrid_GroupBy.html
Hope this helps you.
Hi Stefan,
Thanks for the quick reply. When I say GroupColumns, I didn't mean grouping but banding which is a new feature in WPF xamGrid.For example:
<ig:XamGrid x:Name="dataGrid" AutoGenerateColumns="False"> <ig:XamGrid.Columns> <ig:GroupColumn Key="Group1"> <ig:GroupColumn.Columns> <ig:TextColumn Key="Name"/> <ig:TextColumn Key="Location"/> </ig:GroupColumn.Columns> </ig:GroupColumn> </ig:XamGrid.Columns></ig:XamGrid>
In the above code, I have declared one groupColumn and two text columns in it. However, in my case the number of groupColumns are dynamic, so I need to have a way to bind the GroupColumn key with a collection or something. Please could you suggest a way to accomplish this thing using xaml (with MVVM i.e. no code behind).
Hello,
There are two ways to add GroupColumns. The first one is to define them in XAML and the second one is in the Loaded event e.g. of the XamGrid. Since you want to create them dynamically and you don’t want to use code behind, I created a sample project for you where I used Interactions and I handled the Loaded event in the ViewModel, which is the best option for you.
Hello Khanh,
I have created a sample project for you with the functionality you want. Basically I set the DataContext of the XamGrid when a Button is clicked, and also I defined the ColumnLayout in the handler.
Could you help me in this feature? That is, if I have a button on the Window, when I click the button, it will generate a table like that and sits next to it and so on.
I have modified the code but it failed to do so.
I really want a dynamic XamGrid for my project. It would be great if you can convert the XAML code into C#.
Sincerely,
Khanh
As I said in some of my previos posts, all kind of Columns collections are read only and you are not able to bind them, so it seems that the best approach is to use code behind or Interactions. If I think of a better solution, I will let you know.
Thanks for the sample. Isn't there any way that I can bind some sort of collection in the xaml itself, so that N number of GroupColumns will get generated dynamically. i.e.
<ig:GroupColumn Key="{Binding MyCollection}">
Or is there any way I can leverage the indexer binding. Because the sample you have attached, it's not exactly a code behind but ultimately we are doing the same thing.
skataria