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

Having trouble in getting list in GridComboBoxColumn in UWP

4 Answers 64 Views
DataGrid
This is a migrated thread and some comments may be shown as answers.
jignesh
Top achievements
Rank 1
jignesh asked on 03 May 2018, 05:21 PM

Hi,

Having trouble in getting list in GridComboBoxColumn in UWP.   Let me also admit, that i am myself new to UWP, ViewModels and Telerik.  I will try to explain and please ask questions if any. 

I have a page.xaml in which i have declared DataContext.

<Page.DataContext>
        <viewmodels:GridViewModel/>
</Page.DataContext>

 

GridViewModel class has following properties

APFieldList  MyGridFieldList;   it as column1, column2 .... columnN

ObservableCollection<RDictionary> UserRDictionary;

RDictionary is a simple class.

public class RDictionary
    {
        public string Key { get; set; }
        public string Value { get; set; }
    }

I want column2 to be of type GridComboBoxColumn and combobox list should be populated from UserRDictionary. UserRDictionary contents will come at runtime after some user actions like button_click. 

On page.xaml I have defined things as per documentation. 

 <Page.Resources>
        <viewmodels:GridViewModel  x:Key="myresxitems"/>
    </Page.Resources>

and in Grid

<Custom:DataGridComboBoxColumn PropertyName="column2" ItemsSource="{Binding  UserRDictionary, Source={StaticResource myresxitems }}" />

On Button_Click i am populating UserRDictionary as below.

this.gvm1 = (this.DataContext as GridViewModel);
this.gvm1.LoadRDictionaryAsync(this.gvm1.UserSelectedFile);

 

But the combobox is not populating list. Maybe i am doing some silly mistake.  I believe the instance of datacontext and myresxitems are different.  Can someone please guide.  

 

Regards

 

 

 

4 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 08 May 2018, 10:21 AM
Hello Jignesh,

From the provided code-snippet I can tell that you are absolutely right - it seems you are populating the wrong ViewModel instance with items. In the Click event handler you are populating with items the DataContext of the DataGrid instead of the "myresxitems" resource to which the ComboBoxColumn is bound to - because of that no items are added to the column.

I have created a sample project that demonstrates how to populate the ComboBoxColumn as expected with items and at the same time to bind the ItemsSource of the DataGrid to the exact same instance of the ViewModel - please, check it.

Hope this helps.

Regards,
Nasko
Progress 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
jignesh
Top achievements
Rank 1
answered on 08 May 2018, 12:38 PM

Hi Nasko , First i would like to thank you for the time you have given to reply.

The thing is we have an existing application that uses <Page.DataContext>        <viewmodels:GridViewModel/></Page.DataContext>.   and currently we are using SF Grid control. Being new on UWP and will lots of efforts we have arrived to an running app. 

SF is good, but somehow in this app it's UI response has gone slow. I have used Telerik Web controls in past and was quite happy. So i thought to replace grid with telerik.

I would be happy if there is a way to continue using <Page.DataContext> instead of  <Page.Resources>? so that there are least changes to be done in the current app.   Any further inputs. ?

Regards

 

0
Accepted
Nasko
Telerik team
answered on 09 May 2018, 08:33 AM
Hello Jignesh,

You can use ElementName binding to bind to the DataContext of the Page for your ComboBoxColumn and thus to remove the StaticResource. Please, check the modified sample that demonstrates how that could be achieved.

I hope this will fulfill your requirements.

Regards,
Nasko
Progress 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
jignesh
Top achievements
Rank 1
answered on 10 May 2018, 01:00 PM

Sorry for the late reply Nasko,  It was not working for me until i noticed that ElementName=page and 'page' has to be defined at top with x:name.  i thought 'page' was a reserved keyword  :)

But thanks to you...  finally now I am able to get my list in ComboBoxColumn .  Its working for me.   

I am now going to try template columns. 

Regards

Tags
DataGrid
Asked by
jignesh
Top achievements
Rank 1
Answers by
Nasko
Telerik team
jignesh
Top achievements
Rank 1
Share this question
or