Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
60
best way to populate xamdatagrid with dataset (same datatables)
posted

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.

viewmodel.cs


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"]);

}

Design

<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:

* Fill xamdatagrid automatically. I can't access to determinate field to hidden.

    window.xaml

     igDp:FieldLayoutSettings AutoGenerateFields="True" 

* Fill xamdatagrid manually. I create fieldLayouts with code-behind. The grid don't show data correcty (only show customer table).

   window.xaml

   ...    

   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

Parents Reply Children
No Data