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

Set Property by Selection in GridViewComboBoxColumn

3 Answers 207 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Achim
Top achievements
Rank 1
Achim asked on 30 Apr 2014, 09:32 AM
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

3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 01 May 2014, 10:54 AM
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.
 
0
Achim
Top achievements
Rank 1
answered on 05 May 2014, 07:48 AM
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
0
Dimitrina
Telerik team
answered on 05 May 2014, 11:25 AM
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.
 
Tags
ComboBox
Asked by
Achim
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Achim
Top achievements
Rank 1
Share this question
or