Editable ComboBoxColumn

Jan 8, 2009 at 1:48 PM
Hi,

I need an editable ComboBoxColumn for my project.
Trying this:

<tk:DataGridComboBoxColumn Header="Type" Width="Auto" x:Name="cbCustType" SelectedItemBinding="{Binding Path=Typ}">
                <tk:DataGridComboBoxColumn.ItemsSource>
                    <col:ArrayList>
                        <sys:String>Typ1</sys:String>
                        <sys:String>Bellevue</sys:String>
                        <sys:String>Seattle</sys:String>
                        <sys:String>Renton</sys:String>
                    </col:ArrayList>
                </tk:DataGridComboBoxColumn.ItemsSource>
                <tk:DataGridComboBoxColumn.EditingElementStyle>
                    <Style TargetType="ComboBox">
                        <Setter Property="IsEditable" Value="True" />
                        <Setter Property="IsReadOnly" Value="False" />
                    </Style>
                </tk:DataGridComboBoxColumn.EditingElementStyle>
            </tk:DataGridComboBoxColumn>

This allows me to edit the combobox, the bound value will be updated, but if the cell is in non editing mode, there will be no text shown.
If i select one of the items from the combobox, they will be shown in non editing mode.

Has anyone a solution to that?

Thx
Klausf

Jan 13, 2009 at 7:02 AM
Hi Klausf,

I'm using the code below. OK, it is not Xaml but you can convert.
Might be that helps.

Worstcase.

// ComboBox Column
DataGridComboBoxColumn dataGridComboBoxColumn = new DataGridComboBoxColumn ();
dataGridComboBoxColumn.Header =
"HeaderText";
dataGridComboBoxColumn.MinWidth = 100;
dataGridComboBoxColumn.ItemsSource = arraylist
;
b =
new Binding ("field1");
b.Mode =
BindingMode.TwoWay;
dataGridComboBoxColumn.SelectedItemBinding = b;
dg.Columns.Add (dataGridComboBoxColumn);
Jan 21, 2009 at 10:27 AM
Klausf,

I have exactly the same problem... did you find a solution??

THX!!
Jan 21, 2009 at 3:14 PM
Hi,

I did it with a DataGridTemplateColumn:

<UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary>
                    <ObjectDataProvider x:Key="TypeList"/>                   
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>      
 </UserControl.Resources>

<tk:DataGridTemplateColumn Header="TypeSelection" CanUserResize="False" Width="Auto">
        <tk:DataGridTemplateColumn.CellTemplate>
               <DataTemplate>
                      <TextBlock Text="{Binding Path=Type}"/>
               </DataTemplate>
        </tk:DataGridTemplateColumn.CellTemplate>
        <tk:DataGridTemplateColumn.CellEditingTemplate>
                <DataTemplate>
                      <ComboBox IsEditable="True" MaxWidth="120"
                              Text="{Binding Path=Type}" ItemsSource="{Binding Source={StaticResource TypeList}}" >
                      </ComboBox>
                </DataTemplate>
        </tk:DataGridTemplateColumn.CellEditingTemplate>
</tk:DataGridTemplateColumn>

In the UserControl Code I set the 'TypeList':
ObjectDataProvider K = (ObjectDataProvider)FindResource("TypeList");
K.ObjectInstance = MyDynamicListOfTypes;