This is a migrated thread and some comments may be shown as answers.

Advance Empty ComboBox cells

3 Answers 25 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Minh
Top achievements
Rank 1
Minh asked on 05 Feb 2016, 09:57 PM

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" />

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 10 Feb 2016, 01:04 PM
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
0
Minh
Top achievements
Rank 1
answered on 16 Feb 2016, 07:08 PM
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
0
Stefan
Telerik team
answered on 19 Feb 2016, 01:28 PM
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
Tags
GridView
Asked by
Minh
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Minh
Top achievements
Rank 1
Share this question
or