i am trying to bind xamdatagrid to the observable collection.
<Grid>
<ItemsControl x:Name="MyItemContol" ItemsSource="{Binding ViewSetList}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<ItemsControl.ItemTemplate>
<DataTemplate>
<igDP:XamDataGrid DataSource="{Binding ViewSetList}" >
<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout>
<igDP:FieldLayout.Fields>
<igDP:Field Name="PARAMETER">
<igDP:Field.Settings>
<igDP:FieldSettings AllowEdit="False" />
</igDP:Field.Settings>
</igDP:Field>
<igDP:Field Name="VALUE">
</igDP:Field> <igDP:Field Name="UNIT">
<igDP:Field Name="INSTANCE">
</igDP:FieldLayout.Fields>
</igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
and my cs file will look like this
public partial class MainWindow : Window { private ObservableCollection<Parameters> viewSetList = new ObservableCollection<Parameters>(); public MainWindow() { InitializeComponent();
viewSetList.Add(new Parameters() { PARAMETER="abc", INSTANCE="def" , UNIT="hhshhd", VALUE="hahha" });
}
public ObservableCollection<Parameters> ViewSetList { get { return viewSetList; } set { viewSetList = value; } }
public class Parameters: INotifyPropertyChanged { private string parameterName = string.Empty;
public string PARAMETER { get { return parameterName; } set { parameterName = value; } } private string parameterValue = string.Empty;
public string VALUE { get { return parameterValue; } set { parameterValue = value; } } private string parameterUnit = string.Empty;
public string UNIT { get { return parameterUnit; } set { parameterUnit = value; } } private string instance = string.Empty;
public string INSTANCE { get { return instance; } set { instance = value; } }
public event PropertyChangedEventHandler PropertyChanged; private void onPropertyChanged(object sender, string propertyName) { if (this.PropertyChanged != null) { PropertyChanged(sender, new PropertyChangedEventArgs(propertyName)); } } }
Hello AKshay,
The same topic (DataTable inside a cell) is discussed here:
http://ko.infragistics.com/community/forums/t/111416.aspx
You can find there also a sample project.
Hi Nick,
Thanks for the reply. I really appreciate that.
In the above example (i.e
<igDP:Field Name="VALUE"> <igDP:Field.Settings> <igDP:FieldSettings AllowEdit="False" /> </igDP:Field.Settings> </igDP:Field> )
This code represents a field of XAMDatagrid. The value it takes of type String. But it May also takes DataTable as value. (Means Table inside a cell).
I want to make this XamDataGrid field to display value of type string or to display the value of type (Datatable). Please Guide me to How to make this Particular Field to display string value or Datatable (Table inside a value of cell) based on the source data.
i have included a screen shot of image. Means i want to generate output like this ( if the source data is of type datatable) else normal string value it must display
https://drive.google.com/file/d/1U44_hnH_hNzBj0XjGIT7sc61Nd-wG4hD/view?usp=sharing
If you have any example projects, Pls Post it.
Thanks
AKshay
Hello,
Thank you for the code you have sent.
In this example you will also have to set a DataContext, for example the MainWindow. You will also have to use a property rather than a field for the ObservableCollection.
The ItemsControl is control used for displaying a list of items in WPF. The binding of the XamDataGrid's DataSource currently receives only one item from the ObservableCollection. If you want to bind the XamDataGrid to a ObservableCollection inside an ItemsControl you will have to get ObservableCollection from the DataContext using FindAncestor for example :
<igDP:XamDataGrid DataSource="{Binding DataContext.ViewSetList, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MainWindow}}}" >
Keep in mind that binding ItemsControl to an ObservableCollection will create as much Items as there are in the ObservableCollection. This means that if you have two items in the sample there will be two XamDataGrids with two items each.
To illustrate all of the above I have used your code to create a sample.