Dynamically adding and binding columns
I was wondering if it was possible, and if so how, to add "dynamically" columns to a wpf data grid in syncfusion.
Say I have a hypothetical class that has a few properties:
public class Player
{
public string Name { get; set; }
public string Position { get; set; }
public List
}
where PointsPerVenue would be a list an unknown size that lists the points a certain player scores in a certain venue.
now in my ViewModel I would have an ObservableCollection
I would also have a List
so...
public class ViewModel1
{
public ObservableCollection
public List
}
Can I somehow dynamically add the columns where the venues list would be the column header's and the cells would be bound to the appropriate member of the Player's PointsPerVenue list?
Thanks!
Thanks for using Syncfusion products.
we have prepared a sample as per your query and please find the sample from the attachment.
In the sample, we have achieved your requirement by binding the Venus as like complex property binding and it is not possible to bind a collection which a collection with it. if you want to achieve your requirement, you can have separate collection and that can be bound to a column or else you can use nested grid.
Please let us know if you have queries.
Thanks,
Sankar
92920-1093393862_f0ced6d7.zip
Thank you for your update.
We have
analyzed your query and we have achieve your requirement by using the following
code snippet.
Code
Snippet[Xaml]:
|
<syncfusion:GridDataControl x:Name="DataGrid" ItemsSource="{Binding GDCSource}" ShowAddNewRow="False" AutoPopulateColumns="False" local:GDCAttachedProperty.DynamicColumns="{Binding VisibleColumns}"> </syncfusion:GridDataControl> |
We have
prepared a sample based on this and it can be download from the following
location.
Sample
Location: GridDataControl_VisibleColumnsBinding.zip
Please let
us know if you have any questions.
Regards,
Raja sekar.G
Hi Darren,
We apologies for the delay caused.
The provided sample was unable to download at you end might be because of our server issue. We have reloaded the sample again and could you please check now.
Sample: GridDataControl_VisibleColumnsBinding.zip
Please let us know if you have any queries.
Gobinath A
Please find the sample from the following location,
Sample Link: http://www.syncfusion.com/downloads/support/forum/103058/ze/GridDataControl_VisibleColumnsBinding83567388
Regards,
Jayapradha
We have prepared a sample as per your requirement. In this sample, we have created dynamic VisibleColumns using Indexer Property binding.
Please refer the below code example
C#
|
private List<GridDataVisibleColumn> Getvisiblecolumn() { List<GridDataVisibleColumn> list = new List<GridDataVisibleColumn>(); for (int i = 0; i < 6; i++) { var bind = new System.Windows.Data.Binding() { Path =new System.Windows.PropertyPath($"ColumnArray[{i}].Text") }; list.Add(new GridDataVisibleColumn() // DynamicColumns { MappingName = $"ColumnArray[{i}].Text", Binding = bind, //Must set this property to let the GridDataControl know the type of property, you are binding when using arrarys VisibleColumnType = typeof(string) }); } return list; } private ObservableCollection<Data> Getsource() { ObservableCollection<Data> items = new ObservableCollection<Data>(); if (items != null) { for (int i = 0; i < 6; i++) { Data data = new Data(); for (int j = 0; j < 6; j++) { data.ColumnArray[j] = new Model(); data.ColumnArray[j].Text = "customer" + i; } items.Add(data); } } return items; } |
Please find the sample from the below location:
http://www.syncfusion.com/downloads/support/forum/103058/ze/GridDataControl_VisibleColumnsBinding_-_Array-1073497387
Please let us know if you have queries.
Regards,
Srinivasan
In GridDataControl, while binding columns dynamically the same value updated in all rows of same column when editing the data. This is actual behavior of GridDataControl. So, we have recommended you to use only SfDataGrid in your application and currently we have implemented many features in SfDataGrid. SfDataGrid has been designed based on the WPF template-based architecture which provides support to customize the Grid easily. Comparatively, the performance of SfDataGrid control is better than the GridDataControl.
UG Link: http://help.syncfusion.com/wpf/sfdatagrid/overview
Please let us know if you have any concerns.
Regards,
Srinivasan
- 12 Replies
- 10 Participants
-
OA Ophir Aharoni
- Mar 27, 2012 03:36 PM UTC
- Apr 20, 2016 01:28 AM UTC