Advance Empty ComboBox cells

4 posts, 0 answers
  1. Minh
    Minh avatar
    43 posts
    Member since:
    May 2014

    Posted 05 Feb Link to this post

    I used this method to fix the empty combo box

     

    http://docs.telerik.com/devtools/wpf/controls/radgridview/troubleshooting/blank-cells.html

     

    I have a Usercontrol called relationship that uses that fix. 

    At the moment I have to create 4 different UserControls because each is pointing to a different viewmodel. Is there a way to have it dynamic so it can point to any.

    <UserControl.Resources>
        <local:MainPageViewModel1 x:Key="mainPageViewModel1" />
        <local:MainPageViewModel2 x:Key="mainPageViewModel2" />
        <local:MainPageViewModel3 x:Key="mainPageViewModel3" />
    </UserControl.Resources>
    ...
    <telerik:GridViewComboBoxColumn Header="Category"
            DataMemberBinding="{Binding CategoryID}"
            ItemsSource="{Binding Path=Categories, Source={StaticResource CHOOSE CORRECT VM}}"
            DisplayMemberPath="CategoryName"
            SelectedValueMemberPath="CategoryID" />

  2. Stefan X1
    Admin
    Stefan X1 avatar
    514 posts

    Posted 10 Feb Link to this post

    Hello Minh,

    You should be able to define the same binding of the ItemsSource property at runtime through the BindingOperations class. For example, if we assume that there is a Countries property defined in the view model, and the GridViewComboBoxColumn's UniqueName is Country, you can use an approach as follows.
    Binding comboBinding = new Binding("Countries") { Source = new MyViewModel() };
    BindingOperations.SetBinding(((GridViewComboBoxColumn)this.pilotsGrid.Columns["Country"]),
        GridViewComboBoxColumn.ItemsSourceProperty, comboBinding);

    Hope this helps.

    Regards,
    Stefan X1
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Minh
    Minh avatar
    43 posts
    Member since:
    May 2014

    Posted 16 Feb Link to this post

    Hi Stefan,

    So how would I apply this fix if the ItemsSource were to cascade? 

    http://www.telerik.com/forums/cascading-combo-boxes-with-a-static-resource#SEK90uikoEiv_Stj6EM4Rg
  5. Stefan X1
    Admin
    Stefan X1 avatar
    514 posts

    Posted 19 Feb Link to this post

    Hi Minh,

    If I am understanding your requirement correctly, you can reuse the approach suggested in my previous post by, simply passing the selected item from the DataGrid as a string for the binding.
    private void BindComboBox(string propertyName)
    {
        Binding comboBinding = new Binding(propertyName) { Source = new MyViewModel() };
        BindingOperations.SetBinding(((GridViewComboBoxColumn)this.pilotsGrid.Columns["Country"]),
            GridViewComboBoxColumn.ItemsSourceProperty, comboBinding);
    }

    Can you please clarify whether this suits your needs or I am missing something?

    Best Regards,
    Stefan X1
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top