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

gridview comboboxcolumn not able to update

6 Answers 214 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Neogeo
Top achievements
Rank 1
Neogeo asked on 31 Jul 2012, 08:08 AM
Have a PersonInCharge of List type Person in my ViewModel which bind to a GridView.

A comboboxcolumn in the grid, with ItemsSource of a PeopleList of List type Person

the grid shows well, but when i select different items in the combobox, it always return to the original value.

also the > in the grid leftmost column is always on row 1 instead of the highlighted row

anything wrong?


<telerik:RadGridView x:Name="PersonInCharge" Margin="5,5,5,0" Height="100" ShowGroupPanel="False" AutoGenerateColumns="False"
                 ItemsSource="{Binding Path=PersonInCharge}" CanUserInsertRows="True">
                <telerik:RadGridView.Columns>
                    <telerik:GridViewComboBoxColumn x:Name="cbPersonInCharge"  Header="Person In Charge" UniqueName="PersonInCharge" EditTriggers="CellClick"
                                                             
                                                            ItemsSource="{Binding Path=PeopleList}"     DataMemberBinding="{Binding Person}"
                                                            SelectedValueMemberPath= "PeopleList/Person.ID}"   >                                                       
                        <telerik:GridViewComboBoxColumn.EditorStyle>
 
                        </telerik:GridViewComboBoxColumn.EditorStyle>
                        <telerik:GridViewComboBoxColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel>
                                    <TextBlock Text="{Binding Path=FirstName}" />
                                    <TextBlock Text="{Binding Path=LastName}"/>                            
                                </StackPanel>
                            </DataTemplate>
                        </telerik:GridViewComboBoxColumn.CellTemplate>
 
                        <telerik:GridViewComboBoxColumn.ItemTemplate  >
                            <DataTemplate>
                                <StackPanel>
                                    <TextBlock Text="{Binding Path=FirstName}" />
                                    <TextBlock Text="{Binding Path=LastName}"/>
                                </StackPanel>
                            </DataTemplate>
                        </telerik:GridViewComboBoxColumn.ItemTemplate>
                    </telerik:GridViewComboBoxColumn>

6 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 31 Jul 2012, 10:29 AM
Hi Neo,

I might be missing something, but it seems to me that the way you set SelectedValueMemberPath is slightly wrong - why do you need the " } " at the end ? Is Person property of a particular type or is it just a string property for example ?
Could you provide the implementation of your business objects ?
As for the second issue, the " > " is for the current item, not the selected one. If you want them to coincide, you can set IsSynchronizedWithCurrentItem property of RadGridView to "True". 

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Neogeo
Top achievements
Rank 1
answered on 31 Jul 2012, 12:08 PM
sorry the } is a typo but that does not the problem even if i remove that.

PersonInCharge has a property of type Person
PeopleList is a List<Person>
I need to bind the combobox to the Person type , not a property as i am using EF
0
Maya
Telerik team
answered on 01 Aug 2012, 11:25 AM
Hello Neo,

My recommendation would be to run through our online documentation and demos for a reference on how to define GridViewComboBoxColumn. Generally, the idea is to bind two different data sources and the connection between the two of them is the corresponding properties set for DataMemberBinding and SelectedValueMemberPath.

All the best,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Neogeo
Top achievements
Rank 1
answered on 03 Aug 2012, 05:01 PM
I have reviewed all the document and cannot get it working.

1. the RadGridView ItemsSource binding to the List<Person> and it is showing up right
2. SelectedValueMemberPath ="" as I am binding to an object itself
3. DisplayMemberPath="LastName" which is showing correctly in the drop down
4. DataMemberBinding="{Binding Path=.}" as I am binding to the items in the List<Person>

Everything is showing up right, there is no binding error in the output window.

However, when I run and try to change the person on each row, it always bounce back to the original value when lost focus.
0
Neogeo
Top achievements
Rank 1
answered on 04 Aug 2012, 04:07 AM
In your sample of binding to collection:
<telerik:RadGridView x:Name="RadGridView1" AutoGenerateColumns="False">
<telerik:RadGridView.Columns>
<telerik:GridViewComboBoxColumn DataMemberBinding="{Binding Path=State}" DisplayMemberPath="Name" SelectedValueMemberPath="" />
</telerik:RadGridView.Columns>
</telerik:RadGridView>

the DataMemberBinding is still binding to a property "State", but if I need to bind to the items in the Collection, not a property, I could not do that.

I have tried DataMemberBinding="{Binding Path=.}" or  DataMemberBinding="{Binding Path=/}"  or DataMemberBinding="{Binding Path=PersonInCharge}"  but all are not working. In runtime whatever selected will be bounce back to the original value.

MY other grid are doing ok with binding to a property like your sample.
0
Neogeo
Top achievements
Rank 1
answered on 06 Aug 2012, 08:18 AM
The only way I could get it working is by wrapping my items in another type and turn it into a property.

If you have better ways to bind a collection of items directly to a comboboxcolumn in a grid please share. thanks.
Tags
GridView
Asked by
Neogeo
Top achievements
Rank 1
Answers by
Maya
Telerik team
Neogeo
Top achievements
Rank 1
Share this question
or