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

ToString() DataMemberBinding

4 Answers 464 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tony
Top achievements
Rank 1
Tony asked on 15 Jul 2011, 12:33 PM
I'm considering moving to Telerik grids.  One of the issues I've come up against is that it doesn't look like I can perform bindings which relate to the bound objects ToString() method.

With WPF Toolkit DataGrids I could have a binding on a list view which looked like:

Binding="{Binding}"

This would mean that the ToString() method on the relivant object in the bound collection would be called and displayed.

On Telerik controls if I perform a binding such as:

DataMemberBinding="{Binding}":

Then I do not see this behaviour.  Is this feature missing from your controls or do I have to approach this in another way?  This is something I would really like to be able to do as it allows me to display composite data in a single field.

Thanks

4 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 15 Jul 2011, 12:51 PM
Hello Tony,

That is definitely not true.

Please check out the sample project that I have attached.

Best wishes,
Ross
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Tony
Top achievements
Rank 1
answered on 15 Jul 2011, 01:14 PM
Thanks for clarifying that this should work.  Let me now expand on my previous post.

The particular binding I'm having a problem with is on a GridViewComboBoxColumn, see below:

<telerik:GridViewComboBoxColumn
                    Width="75" 
                    IsReadOnly="False" 
                    Header="VAT"
                    CellStyle="{StaticResource RadGridEditableCellStyle}"
                    ItemsSource="{Binding Source={StaticResource VatCodesSource}}"
                    DisplayMemberPath="{Binding}"
                    SelectedValueMemberPath="VatId"
                    DataMemberBinding="{Binding VatId, UpdateSourceTrigger=PropertyChanged}"/>

The result of this was a combobox with a number of blank items, even though the ToString() method on the bound type returns values along the lines of "S (20.00%)"

However (and this is where it gets a little strange), after my first post I decided, as a temporary measure, to bind to a property called "Rate" on the combos ItemsSource binding and StringFormat this, expecting the result to be along the lines of "20.00".  However what actually happened was that the ToString() method seems to have been called (I'm assuming because of the StringFormat) on the bound object so I got the results I hoped for in the first place, i.e. "S (20.00%)".   

<telerik:GridViewComboBoxColumn
                    Width="75" 
                    IsReadOnly="False" 
                    Header="VAT"
                    CellStyle="{StaticResource RadGridEditableCellStyle}"
                    ItemsSource="{Binding Source={StaticResource VatCodesSource}}"
                    DisplayMemberPath="{Binding Rate, StringFormat=F2}"
                    SelectedValueMemberPath="VatId"
                    DataMemberBinding="{Binding VatId, UpdateSourceTrigger=PropertyChanged}"/>

While I've now got the results I wanted in the first place could you investigate this particular scenario?  I don't really want to leave my code like this as it may become problematic in the future.

Thanks for your help
0
Accepted
Rossen Hristov
Telerik team
answered on 15 Jul 2011, 01:32 PM
Hello Tony,

As it name implies, the DisplayMemberPath is a Path and not a Binding.

You should specify that you want the entire object (i.e. ToString()) like this:

DisplayMemberPath="."

The dot means no path, i.e. give me the whole object.

Please, read this in case you have not.

Kind regards,
Ross
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Tony
Top achievements
Rank 1
answered on 15 Jul 2011, 01:39 PM
Looks like I've had a bit of a brain fart.  Sorry about that!
Tags
GridView
Asked by
Tony
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Tony
Top achievements
Rank 1
Share this question
or