Hello,
I'm using xamdatagrid in my proyect. I have a dataset with 2 datatables (customers and offices , relation 1 customers have a lot of offices). How can I should populate xamdatagrid with this information? I show you my project code.
public DataTable DtResult { get { return _dtResult; } set { _dtResult = value; RaisePropertyChanged("DtResult"); } }
public void LoadCustomers()
{
dtCustomers = Controller.GetClients();
dtOffices = Controller.GetOffices();
DataSet ds = new DataSet();
ds.Tables.Add(dtCustomers);
ds.Tables.Add(dtOffices);
_ds.Relations.Add("Customer", _ds.Tables[dtCustomers.TableName].Columns["CUS_CUSTOMER"], _ds.Tables[dtOffices.TableName].Columns["OFF_CUSTOMER"]);
}
<igDp:XamDataGrid Height="500" Width="900" Name="dgRegistros" DataSource="{Binding UpdateSourceTrigger=PropertyChanged}" DataContext="{Binding DtResult}" Theme="RoyaleStrong" GroupByAreaLocation="None" FontSize="16" FontFamily="Arial Rounded MT Bold">
<igDp:XamDataGrid.FieldSettings> <igDp:FieldSettings AllowRecordFiltering="True" AllowEdit="False" Width="Auto" AutoSizeOptions="All"/> </igDp:XamDataGrid.FieldSettings> <igDp:XamDataGrid.FieldLayoutSettings> <igDp:FieldLayoutSettings AutoGenerateFields="False" AutoArrangeCells="Default" AllowAddNew="True" AllowDelete="True" AddNewRecordLocation="OnBottomFixed"/> </igDp:XamDataGrid.FieldLayoutSettings>
</igDp:XamDatGrid>
I'm trying fill the xamdatagrid through two ways:
window.xaml
igDp:FieldLayoutSettings AutoGenerateFields="True"
...
igDp:FieldLayoutSettings AutoGenerateFields="false"
window.cs
foreach (DataTable dt in ViewModelLocator.CustomerViewModel.DtSet.Tables) { FieldLayout fl = new FieldLayout();
foreach (DataColumn dc in dt.Columns) { Field f = new Field(dc.ColumnName, dc.Caption); f.Width = FieldLength.Auto;
fl.Fields.Add(f); }
dgRegistros.FieldLayouts.Add(fl); }
//If I dont put this line, the grid dont load data although I defined DataContext from xaml.
MyGrid.DataContext = ViewModelLocator.CustomerViewModel.DtResult;
....
I'm a little confused
Regards
Hello Peter,
Thank you for your post. I have been looking into it and I created a sample project for you which shows how to bound to DataSet. Basically the parent FieldLayout should have a Field with a name equal to the relation name of your dataset. I also change the binding for the DataContext, I used RelativeSource, because the DataContext of the binding is not the Windows itself. Please let me know if this helps you or you have other question on this matter.
Looking forward for your reply.
Thanks for your work. I have modificated the project and I added a viewmodel (MVVM light) and a command in xaml. I can't view data with my modifications. ¿Can you review the project? I add in attached zip a library folder becouse you need same dll's to run the application.
I have been looking into your sample I modified the Bindings for the DataSource and DataContext, because there were binding errors, but even I correct them the data wasn't showing. I noticed that if a select the XamDataGrid with Snoop e.g. the binding is executed and the DataSource is set. I tested this with the MS DataGrid and the behavior was the same. I suspect this is related to the design pattern you are using - Service Locator. Since I am not well aware of it I can suggest you ask in the MSDN forums where you can get an answer from a Microsoft expert.
Regards,
Stefan
Thanks. The command not works in any xamdatagrid event? Do you have any answer? The command works in window event.
I have been looking into the command and it doesn't work in window or datagrid neither, because you use an InvokeCommandAction and pass a method, not a command. Here you can see how to use commands and methods with EventTriggers:
http://social.technet.microsoft.com/wiki/contents/articles/18199.event-handling-in-an-mvvm-wpf-application.aspx
Hope this helps you.