GridViewComboBoxColumn display selected value OR validate correctly

6 posts, 0 answers
  1. jen
    jen avatar
    63 posts
    Member since:
    Jun 2009

    Posted 15 Oct 2013 Link to this post

    version : 2013.2.611.1050

    I can't seem to get GridViewComboBoxColumn set up in a way to make this simple scenario to work correctly.
    If I set it up so that the selected value displays correctly in view mode, then a validation error shows -> "Input is not in correct Format"
    If I set it up so the validation works correctly, then the selected Value will not display.

    My DataModel

    MainItem :Entity
    Guid MainItemId
    Guid UnitTypeId
    dms_UnitType dms_UnitType (entity sets up this funny naming by default)

    dms_UnitType : Entity
    Guid UnitTypeId
    String Name

    The Grid Contains a List of MainItem. The unit type ItemSource is a List<dms_UnitType> exposed from the viewModel.

    If not in a grid, my combo box would look like this:
    <telerik:RadComboBox ItemsSource="{Binding UnitTypes}"
                                          DisplayMemberPath="Name" 
                                          SelectedItem="{Binding dms_UnitType, Mode=TwoWay}" />

    Translated into a GridViewComboBoxColumn I believe it should look like this:
      <telerik:GridViewComboBoxColumn Header="Unit Type" 
                                                                DataMemberBinding="{Binding dms_UnitType, Mode=TwoWay}"
                                                                ItemsSource="{Binding UnitTypes}"
                                                               DisplayMemberPath="Name"
                                                                SelectedValueMemberPath="Name" />

    When set like this the selected value displays correctly in view mode, but I get a validation error "Input is not in correct Format". It looks like its trying to assign the SelectedValueMemberPath to my databinding, using a converter. My DataBinding wants the entire object selected from the list to be assigned, not the displayed value. Without SelectedValueMemberPath the Selected value does not display correctly in view mode.

    To fix the validation I set it to select the Item's ID instead of the item itself:
      <telerik:GridViewComboBoxColumn Header="Unit Type" 
                                                                DataMemberBinding="{Binding UnitTypeId, Mode=TwoWay}"
                                                                ItemsSource="{Binding UnitTypes}"
                                                                DisplayMemberPath="Name"
                                                               SelectedValueMemberPath="UnitTypeId" />

    When set like this the validation works correctly, but once again the selected value will not show once you exit edit mode.


    I can't seem to get this simple scenario to work correctly. Any help would be greatly appreciated.    

  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 18 Oct 2013 Link to this post

    Hi,

    Have you tried configuring it like so:

    <telerik:GridViewComboBoxColumn Header="Unit Type"
        DataMemberBinding="{Binding dms_UnitType, Mode=TwoWay}"
        ItemsSource="{Binding UnitTypes}"
        DisplayMemberPath="Name"
        SelectedValueMemberPath="UnitTypeId" />


    I would suggest you to follow the instructions for configuring the column from our online documentation. You can also check this online demo

    Regards,
    Didie
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    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 >>
  3. DevCraft banner
  4. jen
    jen avatar
    63 posts
    Member since:
    Jun 2009

    Posted 18 Oct 2013 Link to this post

    When I configure it as you've suggested I get the "Input is not in correct Format" validation error.
    In my output I get this:

    System.Windows.Data Error: ConvertBack cannot convert value '25e2df37-41a6-41b6-aa8f-0d8b2dfa6d73' (type 'System.Guid').
    BindingExpression: Path='dms_UnitType' DataItem='MainItem : eb980f34-2318-4ee3-bad8-b1fc51ac6677' (HashCode=6964713);
    target element is 'Telerik.Windows.Controls.RadComboBox' (Name='');
    target property is 'SelectedValue' (type 'System.Object')..
    System.InvalidOperationException: Can't convert type System.Guid to type UnitInventoryService.Web.dms_UnitType.

    what you've suggested is basically saying to bind the Guid to the dms_UnitType type.

    I get the impression SelectedValueMemberPath is being used for two things, both the display name and the selected Value binding. But in my case they need to be separate values. I need the display to be the name and the binding to be the item from the list (or the ID property).

  5. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 22 Oct 2013 Link to this post

    Hi,

    Please ensure you have configured the column as explained. Besides the information in our online documentation, you can download an example with GridViewComboBoxColumn from our SDK Repository here and here

    I hope they will help you find the issue in your solution. 
      

    Regards,
    Didie
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    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 >>
  6. jen
    jen avatar
    63 posts
    Member since:
    Jun 2009

    Posted 22 Oct 2013 Link to this post

    The solution is to NOT set the SelectedValueMemberPath when binding to the object from the list.
  7. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 22 Oct 2013 Link to this post

    Hello,

    Thank you for sharing the solution you found with the community. 

    Regards,
    Didie
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    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 >>
Back to Top
DevCraft banner