Good morning
I am facing a really big problem in binding my fields, which are all XamComboBoxEditors, to the XamDataGrid
In my database I have 2 Tables:
Account
public int AccountId { get; set; }
public string Code { get; set; }
public string Code2 { get; set; }
public string Name { get; set; }
public int Parent { get; set; }
and Acc_Link
public int Acc_LinkId { get; set; }
public string Acc_LinkTitle { get; set; }
I need to display in my XamDataGrid 3 combobox columns:
Account Title combobox which contains all the Acc_LinkTitles in the Acc_Link table
A Code combobox which contains all the codes in Account table
A Name combobox which contains all the names in Account table
In Order to facilitate my work, I created a class called Acc_LinkObsrvable that includes the above fields
but no matter how I try, nothing displays in the XamDataGrid when I run the code. I tried adding the code in the FieldInitialized event in the main so that it would load when the code it run but again nothing appeared
I will post my code, please help me.
Acc_LinkObsrvable class:
public string Acc_LinkTitle { get; set; }
public string Code { get; set; }
public string Name { get; set; }
XAML:
<igDP:XamDataGrid DataSource= "{Binding Path=Acc_LinkObservable}" Name="Account_Info_XamDataGrid" FieldLayoutInitialized ="Account_Info_XamDataGrid_FieldLayoutInitialized" BindToSampleData="False" FieldLayoutInitialized = "Account_Info_XamDataGrid_FieldLayoutInitialized">
<igWPF:XamDataGrid.FieldLayoutSettings>
<igWPF:FieldLayoutSettings AutoGenerateFields="False" />
</igWPF:XamDataGrid.FieldLayoutSettings>
</igDP:XamDataGrid>
In main window:
private void Account_Info_XamDataGrid_FieldLayoutInitialized(object sender, FieldLayoutInitializedEventArgs e)
{
ComboBoxItemsProvider title_provider = new ComboBoxItemsProvider();
ComboBoxItemsProvider code_provider = new ComboBoxItemsProvider();
ComboBoxItemsProvider name_provider = new ComboBoxItemsProvider();
List<Acc_LinkDTO> Acc_lists = new List<Acc_LinkDTO>();
List<AccountDTO> accounts = new List<AccountDTO>();
FieldLayout fieldLayout = new FieldLayout();
Acc_lists = _Acc_LinkUIAdapter.getAllAcc_Links();
accounts = _AccountUIAdapter.getALlGroup();
//Returns a list of all Account titles
foreach (var x in Acc_lists)
{
int i = 0;
title_provider.Items.Add(new ComboBoxDataItem(i, x.Acc_LinkTitle));
i++;
}
//Returns a list of all codes and names
foreach (var x in accounts)
{
int i = 0;
code_provider.Items.Add(new ComboBoxDataItem(i, x.Code));
name_provider.Items.Add(new ComboBoxDataItem(i, x.Name));
i++;
}
//First column
Style style1 = new Style(typeof(XamComboEditor));
style1.Setters.Add(new Setter(XamComboEditor.ItemsProviderProperty, title_provider));
var fld1 = new Field()
{
Name="Acc_LinkTitle",
Label = "Account Title",
AlternateBinding = new Binding("Acc_LinkDTO.Acc_LinkTitle"),
EditorStyle = style1,
EditorType = typeof(XamComboEditor)
};
e.FieldLayout.Fields.Add(fld1);
//Second column
Style style2 = new Style(typeof(XamComboEditor));
style2.Setters.Add(new Setter(XamComboEditor.ItemsProviderProperty, code_provider));
var fld2 = new Field()
{
Name="Code",
Label = "Code",
AlternateBinding = new Binding("AccountDTO.Code"),
EditorStyle = style2,
EditorType = typeof(XamComboEditor)
};
e.FieldLayout.Fields.Add(fld2);
//Third column
Style style3 = new Style(typeof(XamComboEditor));
style1.Setters.Add(new Setter(XamComboEditor.ItemsProviderProperty, name_provider));
var fld3 = new Field()
{
Name="Name",
Label = "Name",
AlternateBinding = new Binding("AccountDTO.Name"),
EditorStyle = style3,
EditorType = typeof(XamComboEditor)
};
e.FieldLayout.Fields.Add(fld3);
}
This example demonstrate different approach. All fields defined in the XAML. And the ComboBoxField is used instead of the XamComboEditor.
MainWindow.xaml
MainWindow.xaml.cs
CategoriesList.cs
Product.cs
The following class is copied from the Infragistics SDK.
ObservableModel.cs