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?
Hi nick,
I am using items control for one use case in my project.
Any update on this?
Yes it looks like a binding issue.
By default the XamDataGrid's the Fields collection will be automatically populated with Fields for every property in the underlying data(AutoGenerateFields is set to true). If you want to explicitly use it or set it to false you should always us it with the enclosing tags:
<igDP: XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AutoGenerateFields="False" />/igDP: XamDataGrid.FieldLayoutSettings>
In your scenario if you have not set it and the XamDataGrid which should show the DataTable is blank in most cases you will be notified for a binding issue in the Output window.
The best option in this case and to be sure what is causing this will be if you can create a runnable project which reproduces the issue. You can upload it as a zip file. Such a project will help to debug and test what is causing this.
Hi Nick,
when i added content presenter to the xamdatagrid it showed data. But it does not have any cell borders
<DataTrigger Binding="{Binding Path=DataItem.TABLE_DATATYPE}" Value="True"> <Setter Property ="ContentTemplate"> <Setter.Value> <DataTemplate> <igDP:XamDataGrid DataSource="{Binding Path= ParameterList/TABLEDATA}" Height="Auto" ScrollViewer.VerticalScrollBarVisibility="Hidden" Theme="Office2010Blue" AutoFit="True" BorderBrush="DarkGray" BorderThickness="0.8" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" GroupByAreaLocation="None" ScrollViewer.HorizontalScrollBarVisibility="Hidden" > <ContentPresenter Content="{Binding }"/> </igDP:XamDataGrid> </DataTemplate>
</Setter.Value> </Setter> </DataTrigger>
like this :
https://drive.google.com/open?id=1nOkjRpv8JpNFXytubZOVGCanjTE89bX9
Now i think that this may be issue with the content presenter.
Do you know why it is displaying without any cell borders?
Thank you for the code you have sent.
I will suggest taking a look at this topic:
https://es.infragistics.com/community/blogs/andrew_smith/archive/2009/12/09/common-style-issues-when-using-the-theme-property.aspx
There is an explanation of Common Style Issues when using the Theme property. There are several examples, also how to use the BasedOn property.
Thanks For the reply. But it is not theme issue.
I am attaching the Project. I am using Data Trigger to check the value of the variable : "IsTableData". If it is "true" Then the Field "VALUE" should display the table inside the cell. But it is not displaying the Table. Instead it is just printing the value.
i have tried to represent my problem in the attached project. Please help me to display the table inside the Field. If the value of the IstableData = True
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
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
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
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?
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>.....