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

Hierarchical Grid with GridViewComboBoxColumn in each level

4 Answers 96 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Reid
Top achievements
Rank 2
Reid asked on 27 Nov 2013, 02:12 PM

Hello,

I have some questions about how the GridViewComboBoxColumn binds to a lookup list in a Hierarchical  scenario.

I have a WPF window that has a RadGridView on it that is displaying the following schema correctly with no comboboxes in any columns, just the integer that binds to the property (SecurityLevel) (relevant columns only)

Application1      SecurityLevel
--------------------------------------------------
   Client1           SecurityLevel
   Module1        SecurityLevel


Application2      SecurityLevel
--------------------------------------------------
        Client1                   SecurityLevel
        Client2                  SecurityLevel
        Module1                SecurityLevel

So the main grid's ItemSource is sourced from the "ApplicationAccess" property of the main view model  That object is a List<> of UserApplicationAccessViewModel  objects.  That view model has two nested properties, "ClientAccess" and "ModuleAccess". Each are  List<> members containing their respective ViewModel types, UserClientAccessViewModel and UserToolModuleAccessViewModel.

Each view model, including the primary application view model, UserApplicationAccessViewModel  contains this "SecurityLevel" property which is an integer.  The list that contains those SecurityLevel objects is an adjacent member of each viewModel class.  So my intent is to bind that list to the GridViewComboBoxColumn of each row at each level.  So the user selects a value from the combobox lookup which sets the SecurityLevel property.

{relevant members of each view model}
public List<SecurityLevel> SecurityLevels { get; set; }
public int SecurityLevel { get; set; }

I have found some posts here that have demos for this funtionality at the single level but have not found any that demonstrate it at a Hierarchical level.

This is the markup for the GridViewComboBoxColumn at the top level.

<telerik:GridViewComboBoxColumn x:Name="Application_SecurityLevelSelection_ComboBox"
      DataMemberBinding="{Binding SecurityLevels}"
      Width="100"
      Header="SecurityLevel"
      DisplayMemberPath="FriendlyName"
      SelectedValueMemberPath="SecurityLevel"
      />

I am tapped into the DataLoading event of the grid to format some behaviour of the child grids.  Is this event the key to building and binding this list?

I can databind the column above by name to the list in the main view model and it displays the list correctly but is not binding to each row.  No SecurityLevel is selected in the dropdown list when the record shows, and when you select one and move to another row (another application) the selection dissapears.    Which seems normal because it has to be bound to each row.

If anyone can offer some suggestions here I would appreciate it.

Thanks,
Reid









4 Answers, 1 is accepted

Sort by
0
Reid
Top achievements
Rank 2
answered on 27 Nov 2013, 03:59 PM
Update: Using the DataLoading event I was able to fill the top Application level row Combobox with values.  I assume the same logic would work for the child tables in that event handler.

The issue now is that you cannot leave the column.  It highlights with a red border and won't let you change rows or do anything other than pick another selection.  This appears to be a Validation error.  The viewmodel class does not have any data annotations for these members.

Is there another event I should be hooking to handle this?

Thanks again!

Reid
0
Reid
Top achievements
Rank 2
answered on 28 Nov 2013, 12:58 PM
Update #2:

I set ValidationOnDataErrors="None" and the Validation lock stopped but two things are happening:

1) The ComboBox is not getting set with the value in the record when the grid loads.
2) When you make a selection and change rows to another record the selection dissapears and the combobox shows nothing selected.

I have also added this to the column markup above:
ItemsSourceBinding="{Binding Path=SecurityLevels}"


Thanks!

Reid
0
Accepted
Dimitrina
Telerik team
answered on 28 Nov 2013, 01:20 PM
Hi Reid,

The reason why the selected value disappears would be that the source of the Binding cannot be resolved. I would suggest you to read through our online documentation on how to configure the GridViewComboBoxColumn properly and resolve such an issue.
 
Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Reid
Top achievements
Rank 2
answered on 05 Dec 2013, 12:21 AM
Hello Didie,

Thank you for the links.  The problem was solved by using the DataLoading event as the link indicated:

( ( GridViewComboBoxColumn ) dataControl.Columns["SecurityLevelId"] ).ItemsSource = administrationViewModel.ApplicationSecurityLevels;
           ( ( GridViewComboBoxColumn ) dataControl.Columns["SecurityLevelId"] ).DisplayMemberPath = "FriendlyName";
           ( ( GridViewComboBoxColumn ) dataControl.Columns["SecurityLevelId"] ).DataMemberBinding = new Binding("SecurityLevel");
           ( ( GridViewComboBoxColumn ) dataControl.Columns["SecurityLevelId"] ).DataMemberBinding.Mode = BindingMode.TwoWay;
           ( ( GridViewComboBoxColumn ) dataControl.Columns["SecurityLevelId"] ).SelectedValueMemberPath = "SecurityLevel";
           ( ( GridViewComboBoxColumn ) dataControl.Columns["SecurityLevelId"] ).IsComboBoxEditable = false;
           ( ( GridViewComboBoxColumn ) dataControl.Columns["SecurityLevelId"] ).ValidatesOnDataErrors = GridViewValidationMode.None;

Reid
Tags
GridView
Asked by
Reid
Top achievements
Rank 2
Answers by
Reid
Top achievements
Rank 2
Dimitrina
Telerik team
Share this question
or