Home Forums WPF controls Xceed DataGrid for WPF How to refresh cells that uses a Combobox cell editor?

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

    In short my problem is to get the current selected item in a combobox editcell refreshed when the collection bound to the combobox is changed.

    This is what I’m doing:

    First I have a simple “data container” class:
    public class AccountDef
    {
    public AccountDef(string s, int Id) { Text = s; ID = Id; }

    public string Text { get; set; }
    public int ID { get; set; }

    public override string ToString()
    {
    return Text;
    }
    }

    Then I make an observable collation from this:

    private ObservableCollection<AccountDef> m_AccountDefs =
    new ObservableCollection<AccountDef>();

    Then I have another “data container” class that useses the first one:

    public class Post
    {
    public Post(string text, AccountDef account) { Text = text; Account = account; }

    public string Text {get; set;}
    public AccountDef Account { get; set; }

    public override string ToString()
    {
    return Text;
    }
    }

    Which I also use in an observable collection:

    private ObservableCollection<Post> m_Items = new ObservableCollection<Post>();

    this I bind to a DataGridControl in XAML:
    <Window.Resources>
    <xcdg:DataGridCollectionViewSource x:Key=”griditems”
    Source=”{Binding Source={x:Static Application.Current}, Path=Items}”/>
    </Window.Resources>

    <xcdg:DataGridControl x:Name=”PostGrid”
    ItemsSource=”{Binding Source={StaticResource griditems}}”>

    and finally I define a Combobox cell editor for the Account column in XAML:

    <ObjectDataProvider x:Key=”accounts”
    MethodName=”GetValues”
    ObjectType=”{x:Type c:Account}”>
    <ObjectDataProvider.MethodParameters>
    <x:Type TypeName=”c:Account”/>
    </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>

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

    I attach this to the DataGridControl in the “Code behind”:
    PostGrid.Columns[“Account”].CellEditor =
    this.FindResource(“accountEditor”) as CellEditor;

    This all works fine until I change the Text in one of the AccountDefs (This text is the one shown in the Account column DataGridControl)
    If I open an account combobox (my custom made Cell editor) after the Text has been changed, the modified text shows up fine.
    My question is: How do I refresh the DataGridCotrol so that the column using my custom made Cell Editor reflects the values bound to it?
    (Refresh() doesn’t help!)

    Thanks!

    Imported from legacy forums. Posted by Claus (had 2193 views)

    User (Old forums)
    Member
    Post count: 23064

    I have the same problem. How do you refresh the cell?

    Imported from legacy forums. Posted by Wally (had 3169 views)

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