I want to bind a XamComboEditor to a Cell, where each cell in a row has a different set of data in the combobox, in C# code.
I use a ComboBoxItemsProvider, Fieldsetting and style to set a fieldsetting of a particular cell, through the 'InitializeRecord' event.
But that settings is used for the hole column (or Field for that matter).
Conclusion i get the same data on every row (in de particular column).
In the XamComboEditor dependeny properties is a loaded event, is it possible though that to set the correct XamComboEditor data and how?
Hi,
You need to create a style for each cell with a XamComboEditor and set the data for it through the style. For example on one row I have two XamComboEditors - one for the status and one for the priority. So I create two styles for them:
<Style x:Key="PriorityFieldStyle" TargetType="{x:Type igEditors:XamComboEditor}"> <Setter Property="ItemsProvider"> <Setter.Value> <igEditors:ComboBoxItemsProvider ItemsSource="{Binding Source={StaticResource PrioritiesXml}, XPath=/priorities/priority}" DisplayMemberPath="@text" ValuePath="@id"/> </Setter.Value> </Setter> </Style>
and
<Style x:Key="StatusFieldStyle" TargetType="{x:Type igEditors:XamComboEditor}"> <Setter Property="ItemsProvider"> <Setter.Value> <igEditors:ComboBoxItemsProvider ItemsSource="{Binding Source={StaticResource StatusXml}, XPath=/stats/status}" DisplayMemberPath="@text" ValuePath="@id"/> </Setter.Value> </Setter> </Style>
The data comes from the XmlDataProvider -- like this:
<XmlDataProvider x:Key="PrioritiesXml"> <x:XData> <priorities xmlns=""> <priority text="High" id="0" /> <priority text="Normal" id="2" /> <priority text="Low" id="1" /> </priorities> </x:XData></XmlDataProvider>
<igDP:Field Name="State" Label="Status"> <igDP:Field.Settings>
<igDP:FieldSettings PropertyChanged="FieldSettings_PropertyChanged" EditorStyle="{StaticResource StatusFieldStyle}" CellWidth="150" LabelWidth="150" />
</igDP:Field.Settings></igDP:Field>
<igDP:Field Name="PriorityLevel" Label="Priority"> <igDP:Field.Settings> <igDP:FieldSettings EditorStyle="{StaticResource PriorityFieldStyle}" /> </igDP:Field.Settings></igDP:Field>
There is also an example of this in the XamFeatureBrowser in the Control Composition section of the XamDataGrid samples.
Hope this helps.
This is true for 1 row and 2 columns within 2 comboxen, but what if i want these 2 different comboboxes within 1 column and 2 or more row.
Hi Bastian.
If I understand you correctly, it might have the same reqest. I want to bind two fields to the same cell. I want to bind the Code and the Description of an action from my db into the same "line" in the dropdown.
So lets say the code is "WF_CA" and the Description is "Where Failure corrective action", then I want the ComboBoxItemsProvider to provide the cell with "WF_CA - Where Failure corrective action" and the user only selects that. The ValuePath should still link to the ID of the action.
I'm sorry I am not able to help you.
Christo
Hello Christo,
For this it would be appropriate to create a style the ComboBoxItemProvider and re-template it ( make a custom DataTemplate ) with two TextBoxes inside it, so that you can bind the code and description to each of them.
Hi Poka
I do not follow what you are asking. Can you provide more information please.
Kind regards
How ca i do in visual basic
I have xamcomboeditor.itemsource = Lista -- have array it´s ok but when i want to put name and value it´s not working
xamcomboeditor.DisplayMemberPath ="memdescripcion"
xamcomboeditor.DisplayValueSource = "memid"
can you explain me thanks.
WOW, that was quick
I had an idea like that, but after reading through some of the other forums, I got the idea of just adding when the control initializes. So what I did was the following
<XAML>
<igEditors:ComboBoxItemsProvider x:Key="comboBox_FKActions" />
[... Some other code ...]
<igDP:XamDataGrid x:Name="XamDataGrid"[.... Some other code ....]
[... bla bla bla ...]
<igDP:Field Name="FKAction" Label="Actions"> <!--A setter is added to limit the options the user has--> <igDP:Field.Settings> <igDP:FieldSettings EditorType="{x:Type igEditors:XamComboEditor}"> <igDP:FieldSettings.EditorStyle> <Style TargetType="{x:Type igEditors:XamComboEditor}"> <Setter Property="ItemsProvider" Value="{StaticResource comboBox_FKActions}" /> </Style> </igDP:FieldSettings.EditorStyle> </igDP:FieldSettings> </igDP:Field.Settings> </igDP:Field>
</XAML>
[C#]
public RolesTab() { InitializeComponent(); _dt_Action = _bll_Action.GetActions(); ComboBoxItemsProvider statusProvider = this.TryFindResource("comboBox_FKActions") as ComboBoxItemsProvider; foreach (SecurityDAL.ac_ActionRow row in _dt_Action.Rows) { statusProvider.Items.Add(new ComboBoxDataItem(row.IDAction, row.Action_Code + " - " + row.Action_Description)); } }
Where the _bll_Action just returns a data table.
Hope this might help somone else trying this.
Regards