I want to display the a child table inside a xamdatagrid.
<igDP:XamDataGrid DataSource="{Binding DataContext.ViewSetList,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MainWindow}} }" > <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.Settings> <igDP:FieldSettings AllowEdit="False" /> </igDP:Field.Settings> </igDP:Field>
</igDP:FieldLayout.Fields>
</igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>
I want to bind this <igDP:Field Name="VALUE" > field to another another data table. Is there any possible solutions
Hello AKshay,
Thank you for the code snippet you have provided.
You can use XamDataGrid’s Template Field to create a field with a custom display and edit template. In order to display the DataTable you will need some form of a Grid control. Using this approach I have created a small sample. You can use this as an example of the functionality of the Template Field, which Grid you will use depends solely on your scenario.
Hi NICK,
Thanks For the kind help.
I tried the above mentioned solution but not able to get results. So now i have used cell value presenter to display the table inside a table.
<Window x:Class="TestFast.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:igDP="http://infragistics.com/DataPresenter" xmlns:igEditors="http://infragistics.com/Editors" xmlns:local ="clr-namespace:TestFast" Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="TableData"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}"> <igDP:XamDataGrid DataSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MainWindow}} }" /> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> <Grid> <ItemsControl x:Name="MyItemContol" ItemsSource="{Binding ViewSetList}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"> <ItemsControl.ItemTemplate> <DataTemplate>
<igDP:XamDataGrid DataSource="{Binding DataContext.ViewSetList,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MainWindow}} }" > <igDP:XamDataGrid.FieldLayouts > <igDP:FieldLayout> <igDP:FieldLayout.Fields>
<igDP:Field Name="VALUE" > <igDP:Field.Settings> <igDP:FieldSettings AllowEdit="False" CellValuePresenterStyle="{StaticResource TableData}" /> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="UNIT"> <igDP:Field.Settings> <igDP:FieldSettings AllowEdit="False" /> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="INSTANCE"> <igDP:Field.Settings> <igDP:FieldSettings AllowEdit="False" /> </igDP:Field.Settings> </igDP:Field>
</igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts>
</DataTemplate> </ItemsControl.ItemTemplate>
</ItemsControl> </Grid></Window>
using System;using System.Collections.Generic;using System.Collections.ObjectModel;using System.ComponentModel;using System.Data;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;
namespace TestFast{ /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { //private ObservableCollection<Parameters> viewSetList = new ObservableCollection<Parameters>(); //private ObservableCollection<Parameters> viewSetList = new ObservableCollection<Parameters>(); public ObservableCollection<Parameters> _ViewSetList = new ObservableCollection<Parameters>(); public MainWindow() { InitializeComponent(); DataTable table = new DataTable(); table.Columns.Add("Weight"); table.Columns.Add("Name"); table.Columns.Add("Breed"); table.Columns.Add("Date");
DataRow dt = null; int j = 0;
for (int i = 0; i < 3; i++) { dt = table.NewRow(); j = i; dt["Weight"] = j; dt["Name"] = j + 1; dt["Breed"] = j + 2; dt["Date"] = j + 3; table.Rows.Add(dt); }
ViewSetList.Add(new Parameters() { PARAMETER="abc", INSTANCE="def" , UNIT="hhshhd", VALUE= table}); //ViewSetList.Add(new Parameters() { PARAMETER = "abc2", INSTANCE="def2" , UNIT="hhshhd2", VALUE="hahha2" });
this.DataContext = this;
}
public ObservableCollection<Parameters> ViewSetList { set { _ViewSetList = value; } get { return _ViewSetList; } }
public class Parameters : INotifyPropertyChanged { private string parameterName = string.Empty;
public string PARAMETER { get { return parameterName; } set { parameterName = value; } } private DataTable parameterValue;
public DataTable 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)); } } }}
But the new problem is that it is showing same table inside that cell. But i want to bind only particular value to that cell?
I tried to use the
<igDP:XamDataGrid DataSource="{Binding Path=ViewSetList.Parameters.VALUE, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MainWindow}} }" />
But It is showing empty. Please help?
Thank you for the image you have sent,
You referred in your last post to field VALUE. If you look at it there is a scrollbar which was activated because the XamDataGrid is too small.You will be able to view the XamDataGrid if you increase the CellHeight, for example:
<igDP:XamDataGrid DataSource="{Binding ViewSetList,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MainWindow}} }" > <igDP:XamDataGrid.FieldSettings> <igDP:FieldSettings CellHeight="100"/> </igDP:XamDataGrid.FieldSettings>.....
Hi Nick,
i tried your Suggestion but no table is populated. So i decided to convert Data table to string. and just show the string inside that parent table.
i.e Parameter VALUE = convertDataTableToString(Datatable); //this function will convert data table to string with rows and columns
During the debugging the i checked the Value it is showing like IMAGE 1
https://drive.google.com/open?id=1Ph8T0jAXc73zNANtZ7N3YG3nNHvcBYSx
and final output is like this
https://drive.google.com/open?id=1vsWbI94GSMNqhNP07iqTmJ6T41T2FlII
Will Xamdatagrid will remove the spaces from the string?
I have modified the sample you have sent and added the functionality we discussed. When I run the project there are two XamDataGrids, and the child is populated with DataTable as you can see in the screenshot from my previous post.
Please test this project on your PC; whether or not it works correctly may help indicate the nature of this issue.
If the project does show the XamDataGrid populated, this indicates that something in your application prevents the DataTable to be displayed (e.g. styles, data binding, etc.).
If the project does not work correctly, this indicates either a problem possibly specific to your environment, or a difference in the DLL versions we are using. My test was performed using version 17.1.20171.2073.
Sincerely,NickEntry-Level Software Developer
Thanks Nick. It was a binding issue. I managed to get the table inside a table.
I have couple of questions here.
1. Why you have used Data ParameterList/tableData. Cant we use ParameterList.Tabledata for binding?
2. Is there any good source to learn WPF complex bindings other then MSDN.
Thanks
Akshay
Hello Akshay,
I am glad that you were able to achieve the functionality you were looking for.
You can take a look at Microsoft Docs, especially this topic:
Data Binding Overview
You can find a thorough description about Data Binding
As you can see in the description ("Current Item Pointers"), WPF binds to a collection only by using a view (either a view you specify, or the collection's default view), all bindings to collections have a current item pointer. When binding to a view, the slash ("/") character in a Path value designates the current item of the view. In your scenario in the collection Parameters(ViewSetList) the TableData is a property which represents the current data, which is DataTable.Sincerely,NickEntry-Level Software Developer