Home Forums WPF controls Xceed DataGrid for WPF ComboBox DisplayValue issue

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #25279 |

    Hi.

    I’m struggling to get a Combobox CellEditor to work properly.
    I’m sure I’m just missing something stupid…

    When adding a new row to the grid, the combox work fine.
    (Combo itemsource = collection of a class with Code/Description properties)
    I can select an item viewing the description.

    But as soon as i move off the column it goes blank.
    Hovering over cell shows combo again and the correct description.
    Also the value in the grid’s main collection is also correct… = Code.

    For some reason the nothing gets displayed in cell if it doesn’t have focus.

    Here’s the code.

    XAML:

    xmlns:Custom=”http://schemas.xceed.com/wpf/xaml/datagrid”

    <Custom:DataGridCollectionViewSource x:Key=”items”
    Source=”{Binding}”/>

    <DataTemplate x:Key=”itemDataTemplate”>
    <TextBlock Text=”{Binding Path=Description}”
    TextTrimming=”{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Custom:Cell}}, Path=ParentColumn.TextTrimming}”
    TextWrapping=”{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Custom:Cell}}, Path=ParentColumn.TextWrapping}”/>
    </DataTemplate>

    <DataTemplate x:Key=”itemCellDataTemplate”>
    <ContentPresenter Content=”{TemplateBinding Content}”
    MinHeight=”22″
    ContentTemplate=”{StaticResource itemDataTemplate}”>
    </ContentPresenter>
    </DataTemplate>

    <Custom:CellEditor x:Key=”ItemEditor”>
    <Custom:CellEditor.EditTemplate>
    <DataTemplate>
    <ComboBox BorderThickness=”0″
    Background=”Transparent”
    Foreground=”{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(TextElement.Foreground)}”
    MinHeight=”22″
    VerticalContentAlignment=”Top”
    SelectedValuePath=”ItemCode”
    ItemsSource=”{Binding Source={StaticResource items}}”
    ItemTemplate=”{StaticResource itemDataTemplate}”
    SelectedValue=”{Custom:CellEditorBinding}”>
    <ComboBox.Resources>
    <Style TargetType=”Popup”>
    <Setter Property=”TextElement.Foreground”
    Value=”{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}” />
    </Style>
    </ComboBox.Resources>
    </ComboBox>
    </DataTemplate>
    </Custom:CellEditor.EditTemplate>
    <Custom:CellEditor.ActivationGestures>
    <Custom:KeyActivationGesture SystemKey=”Down”
    Modifiers=”Alt”/>
    <Custom:KeyActivationGesture Key=”Up”
    Modifiers=”Alt”/>
    <Custom:KeyActivationGesture Key=”F4″/>
    <Custom:KeyActivationGesture Key=”Space”/>
    </Custom:CellEditor.ActivationGestures>
    </Custom:CellEditor>

    Code Behind:

    grid.Columns[“ItemCode”].CellEditor = this.FindResource(“ItemEditor”) as CellEditor;
    grid.Columns[“ItemCode”].CellContentTemplate = this.FindResource(“itemCellDataTemplate”) as DataTemplate;

    Imported from legacy forums. Posted by Barry (had 3006 views)

    User (Old forums)
    Member
    Post count: 23064

    OK

    My issues is that I don’t know the correct Syntax for binding the CellContentTemplate to
    the Description field in my combo.

    Please! can anyone help me?
    This looks like really cool control to use in our company, but no use if I can’t even get this small task to work….

    cheers

    Imported from legacy forums. Posted by Barry (had 202 views)

    User (Old forums)
    Member
    Post count: 23064

    Quoted from Butterball:
    ================================================
    But as soon as i move off the column it goes blank.
    Hovering over cell shows combo again and the correct description.
    Also the value in the grid’s main collection is also correct… = Code.

    For some reason the nothing gets displayed in cell if it doesn’t have focus.
    ================================================

    From these symptoms it sounds like your data presenter isn’t working correctly. A simple fix could be to always show the editor. When a cell enters edit mode the contents of the cell are replaced with an edit control.

    I think the content of your cell is an int and the itemCellDataTemplate doesn’t know how to get a “Description” property off of an int when it’s used as the CellContentTemplate. I think if you removed the assignment to the CellContentTemplate you’d see the id integer value.

    There was a bunch of Sample code included with my installation. I would recommend looking through the DataBinding sample which is installed for me at:
    C:\Program Files\Xceed Components\Xceed DataGrid for WPF 1.2\Samples\CSharp\DataBinding

    If I remember correctly, the DataTableDictionary is used to translate the ID (Key) into a DataRow which has the description in it and then a data template is applied for formatting (see your itemCellDataTemplate)

    Imported from legacy forums. Posted by James (had 282 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi.

    I started using a combo as celltemplate yesterday instead of a textbox and it works.
    I’ll implement the dictionary later today.

    Thanks!

    Imported from legacy forums. Posted by Barry (had 3984 views)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.