Set Property by Selection in GridViewComboBoxColumn

4 posts, 0 answers
  1. Achim
    Achim avatar
    9 posts
    Member since:
    Aug 2013

    Posted 30 Apr 2014 Link to this post

    Hello,

    I got some issues with setting a Value in an Object depending on the Selection in a GridViewComboBoxColumn.

    I have a List of Objects bound to a RadGridView. An Object contains a List of valid Value-Objects for a Value-Property the Object has. What I want to do is now bind the List of valid Value-Objects to the ComboBoxes of the Column ( each Object has a different List of valid Value-Objects) and set the Value-Property of the referring Object depending on the SelectedItem in the ComboBox.

    Object ()
    {
    string Name {get; set;}
    int Number {get;set;}
    List<Value> ValidValues;
    Value Value {get; set;}
    bool Visibility {get;set;}
    }

    Value()
    {
    string Description {get;set;}
    string Key {get;private set;}
    }

    <telerik:RadGridView ItemsSource="{Binding Objects}" AutoGenerateColumns="False">
                            <telerik:RadGridView.Columns>
                                <telerik:GridViewDataColumn Header="Nr." DataMemberBinding="{Binding Number}" IsReadOnly="True">
                                </telerik:GridViewDataColumn>
                                <telerik:GridViewDataColumn Header="Name" IsReadOnly="True" DataMemberBinding="{Binding Name}">
                                </telerik:GridViewDataColumn>
                                <telerik:GridViewCheckBoxColumn Header="Visibility" IsReadOnly="True" DataMemberBinding="{Binding IsVisible}">
                                </telerik:GridViewCheckBoxColumn>
                                <telerik:GridViewComboBoxColumn Header="Value"
                                                                Width="250"
                                                                ItemsSourceBinding="{Binding ValidValues}"
                                                                DisplayMemberPath="Description"
                                                                IsComboBoxEditable="False"
                                                                DataMemberBinding="{Binding Key}"
                                                                SelectedValueMemberPath="Key" // I have to set that to Key because otherwise the Combobox is not showing anything when the respective row is not more on focus //
                                                                >
                                </telerik:GridViewComboBoxColumn>
                            </telerik:RadGridView.Columns>
                        </telerik:RadGridView>

    I hope this is enough code to understand what my problem is and offer me some help if possible. Thank you!
    Regards,
    Achim
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 01 May 2014 Link to this post

    Hi,

    You have set  DataMemberBinding="{Binding Key}" for the ComboBoxColumn and I do not see such a property of your Object type. It is a property of the Value type instead.

    You need to set the DataMemberBinding to the respective property of the bound data item (i.e. Object).
    You can learn more about how to configure the column properly in our online documentation here: ComboBox Column.

    I hope this helps.

    Regards,
    Didie
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Achim
    Achim avatar
    9 posts
    Member since:
    Aug 2013

    Posted 05 May 2014 Link to this post

    Hello,

    I did some changes in my code but i do now get an exception System.Windows.Data Error 8: Cannot save value from target back to source. NullReferenceException

    <telerik:GridViewComboBoxColumn Header="Value"
                                                                Width="250"
                                                                ItemsSourceBinding="{Binding ValidValues}"
                                                                DisplayMemberPath="Description"
                                                                IsComboBoxEditable="False"
                                                                DataMemberBinding="{Binding Value, Mode=TwoWay}"
                                                                SelectedValueMemberPath="Key"
                                                                UniqueName="Value"
                                                                >
     </telerik:GridViewComboBoxColumn>

    I hope you can help me with that. It would be nice to know if the Binding is now correct and thus the mistake is in my code-behind.
    Regards,
    Achim
  5. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 05 May 2014 Link to this post

    Hi Achim, 

    We are not aware of such an error caused by the column. It seems like an error caused at your data level.
    Would you please ensure this? You can also check this forum thread where a similar question has already been discussed.

    Regards,
    Didie
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top