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

GridViewComboBoxColumn binding problem

3 Answers 84 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Daniel Nevers
Top achievements
Rank 1
Daniel Nevers asked on 07 Oct 2009, 09:22 AM
Hello,

I've searched the forum but without success! Apparently, I am the only one trying to bind a GridViewComboBoxColumn to a class (instead of simple a int or a string).

All the binding is working fine, the ComboBox is filled in correctly, changing and saving data is working but the GridView doesn't display the value on start (strangely, it is displaying correctly after I choose a value in the ComboBox...)!

I guess there is something missing to make the match between the original value and the values in the ComboBox... but what?

Here is a sample of my faulty code:

The main class of the GridView (note that here we have a Currency class and not a CurrencyID)
public class Fund  
{  
   public virtual string Name { getset; }  
   public virtual Currency Currency { getset; }  

The Currency class
public class Currency : AbstractLinkedClass  
{          
   public virtual string IsoCode { getset; }  

The grid's XAML code
<telerik:RadGridView Grid.Row="3" Margin="0,5,0,5" Name="rgvFund" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" AutoGenerateColumns="False" RowEditEnded="rgvFund_RowEditEnded" ValidationMode="Row">  
    <telerik:RadGridView.Columns> 
        <telerik:GridViewDataColumn Header="Name" DataMemberPath="Name" /> 
        <telerik:GridViewComboBoxColumn Header="Currency" ItemsSource="{Binding}" UniqueName="Currency.IsoCode" DataMemberBinding="{Binding Currency}" DisplayMemberPath="IsoCode" SelectedValueMemberPath="." /> 
    </telerik:RadGridView.Columns> 
</telerik:RadGridView> 

The .cs code behind where currencies are taken from the DB.
rgvFund.Columns[1].DataContext = currencies; 

Any idea why with this code, the Currency column appears empty on load (while Fund.Currency is correctly filled in on start)?

Thank you,

Daniel

3 Answers, 1 is accepted

Sort by
0
Daniel Nevers
Top achievements
Rank 1
answered on 08 Oct 2009, 02:20 PM
Ok, I kept looking for a solution and finally I found a solution by myself!

In my Currency class, I just implemented the Equals(object) method (and the GetHashCode() method) to compare objects using an internal identifier (not shown in the code above).

As I though, the grid was unable to make a match between the currencies in the drop down list and the currency in the current row object. Now everything is working fine!

Anyway! What if (for any kind of business reason), we cannot modify the Equals() method?
Would there be another solution to solve the problem?

Consider this question as resolved but feel free to give another (maybe better) solution!

Best regards,

Daniel
0
Daniel Nevers
Top achievements
Rank 1
answered on 08 Oct 2009, 02:21 PM
Oops, double post (sorry, connection problem).
This one can be deleted.
0
Pavel Pavlov
Telerik team
answered on 12 Oct 2009, 12:51 PM
Hello Daniel ,

Thanks for reporting this issue! Indeed the way you found is the only possible solution I can think of for the moment. Great job ! We are going to revise this logic and if possible find a better way to handle such scenario.

One more time thanks for the feedback ! I have updated your Telerik points.

Regards,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Daniel Nevers
Top achievements
Rank 1
Answers by
Daniel Nevers
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Share this question
or