Hello all,
How to set a field in xamDataGrid to have a value from a ComboBox and not be editable?
Look at my situation:
Into a xamDataGrid I need that a field to be of ComboBox type.
Here the only possible values are the values from ComboBox.
So the end user can not types a value for this field, instead he can choose a value from ComboBox.
To work with ComboBox in xamDataGrid, I found a sample at:
http://help.infragistics.com/Help/NetAdvantage/WPF/2007.1/CLR3.X/HTML/xamDataGrid_Setting_a_ComboBox_for_Use_in_a_Field.html
<Window x:Class="ComboTest.Window1" 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:sys="clr-namespace:System;assembly=mscorlib" Title="Window1" Height="300" Width="300"> <Window.Resources> </Window.Resources> <Grid> <Grid.Resources> <Style TargetType="{x:Type igEditors:XamTextEditor}" x:Key="customComboBoxEditor"> <Setter Property="EditTemplate"> <Setter.Value> <ControlTemplate TargetType="{x:Type igEditors:XamTextEditor}"> <StackPanel> <ComboBox x:Name="cboComboboxEditor" IsEditable="True" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Text, Mode=TwoWay}" > <ComboBoxItem>Quality Assurance</ComboBoxItem> <ComboBoxItem>Accounting</ComboBoxItem> <ComboBoxItem>Development</ComboBoxItem> <ComboBoxItem>Sales</ComboBoxItem> </ComboBox> </StackPanel> </ControlTemplate> </Setter.Value> </Setter> </Style> <XmlDataProvider x:Key="EmployeeData" Source="/Data/Employees.xml" XPath="/employees" /> </Grid.Resources> <igDP:XamDataGrid Grid.Row="0" x:Name="XamDataGrid1" DataSource="{Binding Source={StaticResource EmployeeData}, XPath=employee}"> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AutoGenerateFields="False" /> </igDP:XamDataGrid.FieldLayoutSettings> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Fields> <igDP:Field Name="name" Label="Employee's Name"/> <igDP:Field Name="department" Label="Department"> <igDP:Field.Settings> <igDP:FieldSettings EditorStyle="{StaticResource customComboBoxEditor}" /> </igDP:Field.Settings> </igDP:Field> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid> </Grid></Window>
But this only works when IsEditable="True" ( a ComboBox property ).
If I set IsEditable="False" than when the mouse is over the dropdown list, the list disappear and I can't select something.
Do you have any suggestion to solve my problem?
Best Regards, Liviu
Here is the trick.....
//--code behind
combo.Items.Add("Item2");
}