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

GridViewComboBoxColumn with Enums

1 Answer 912 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Torben
Top achievements
Rank 2
Iron
Torben asked on 23 Mar 2017, 12:01 PM

I have at WPF app with a main window using MVVM and EF.

In the MainView I have RadGridView with a GridViewComboBoxColumn that is bound to a  property on my model,

I would like to use it with a Enum when the user want to edit the value.

XAML in MainView

<Window>
    <UserControl.DataContext>
        <viewModel:MainViewModel/>
    </UserControl.DataContext>
    <Grid>
         <telerik:RadGridView ItemsSource="{Binding MyUserList}">
    <telerik:RadGridView.Columns>
<telerik:GridViewDataColumn Header="ID"
                            DataMemberBinding="{Binding Id}"
IsReadOnly="True" />
<telerik:GridViewComboBoxColumn DataMemberBinding="{Binding UseName}"
ItemsSource="{Binding AvailableUserNameEnum}"
                                UniqueName="UseTheName"
      </telerik:RadGridView.Columns>
      </telerik:RadGridView>
    </Grid>
 </Window>

Code in MainViewmodel

public enumUseNameEnum
{
   NA,
   No,
   Yes
}
public List<UseNameEnum> AvailableUseNameEnum { get; set; }
private void Fill AvailableUseNameEnums()
        {
            AvailableUseNameEnum = new List<UseNameEnum>
            {
                UseNameEnum.Yes,
UseNameEnum.No,
                UseNameEnum.NA
            };
        }
Data from the Table User is hold the this list, that is bound to the grid:
public ObservableCollection<Users> MyUserList { get; set; }

Table User has 2 Columns: ID  and UseName

The Grid shows data fine, except for the UseName Column, that is blank.  When clicked in the combobox , it has data , the 3 options,  but when one is selected the values is not showing in the cell. It is still blank.


1 Answer, 1 is accepted

Sort by
0
Accepted
Dilyan Traykov
Telerik team
answered on 28 Mar 2017, 07:52 AM
Hello Torben,

In this scenario, you can use the EnumDataSource utility in order to bind the GridViewComboBox column.

For your convenience, I'm attaching a sample implementation which you can incorporate into your project. Please let me know if you need any further assistance with this.

Regards,
Dilyan Traykov
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
Torben
Top achievements
Rank 2
Iron
Answers by
Dilyan Traykov
Telerik team
Share this question
or