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

[Solved] GridViewComboBoxColumn Doesn't Always Display Selected Values

4 Answers 296 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Dan Pingel
Top achievements
Rank 1
Dan Pingel asked on 30 Jul 2010, 08:14 PM
Hi,

I'm having an issue with the GridViewComboBoxColumn where the selected values for ALL of my rows don't always display.

The images I've attached show what I mean.  I have no clue how they'll post, but they're attached.

I am writing this using the MVVM pattern, so everything is binding to my View Model.  Also, I'm using RIA Services and the ADO.NET Entity Framework to pull data from my SQL Server Database.

In said database, I have two relevant tables:

Material
ID (int)
GaugeID (int)
Name (nvarchar(63))
Grade (nvarchar(63))
Thickness(numeric(5,4))
WeightPerSquareFoot(numeric(9,4))

Gauge
ID (int)
Name (nvarchar(63))

And, of course, there is a foreign key between Material.GaugeID and Gauge.ID.

So, here's the XAML for my RadGridView:

<telerik:RadGridView Grid.Row="0"
         ItemsSource="{Binding Materials}"
         SelectedItem="{Binding SelectedMaterial, Mode=TwoWay}"
         CanUserResizeColumns="False" CanUserInsertRows="False" CanUserFreezeColumns="False"
         AutoGenerateColumns="False" SelectionMode="Single" ShowGroupPanel="False">
    <telerik:RadGridView.RowStyle>
        <Style TargetType="telerik:GridViewRow">
            <Setter Property="MinHeight" Value="30"/>
        </Style>
    </telerik:RadGridView.RowStyle>
    <telerik:RadGridView.Columns>
        <telerik:GridViewToggleRowDetailsColumn />
        <telerik:GridViewDataColumn Header="Material Name" DataMemberBinding="{Binding Name}" Width="*" />
        <telerik:GridViewComboBoxColumn Header="Gauge" 
                                        DataMemberBinding="{Binding GaugeID}"
                                        ItemsSource="{Binding Gauges}" 
                                        DisplayMemberPath="Name"
                                        SelectedValueMemberPath="ID" 
                                        Width="*"/>
        <telerik:GridViewDataColumn Header="Grade" DataMemberBinding="{Binding Grade}" Width="*" />
        <telerik:GridViewDataColumn Header="Thickness" DataMemberBinding="{Binding Thickness}"  Width="*" />
        <telerik:GridViewDataColumn Header="Wt. / Sq. Foot" DataMemberBinding="{Binding WeightPerSquareFoot}"  Width="*" />
    </telerik:RadGridView.Columns>
</telerik:RadGridView>

And the view model:

private IEnumerable<Material> materials;
public IEnumerable<Material> Materials {
    get { return materials; }
    private set {
        if (value != materials) {
            materials = value;
            RaisePropertyChanged("Materials");
        }
    }
}
private IEnumerable<Gauge> gauges;
public IEnumerable<Gauge> Gauges {
    get { return gauges; }
    private set {
        if (value != gauges) {
            gauges = value;
            RaisePropertyChanged("Gauges");
        }
    }
}
private Material selectedMaterial;
public Material SelectedMaterial {
    get { return this.selectedMaterial; }
    set {
        if (value != this.selectedMaterial) {
            this.selectedMaterial = value;
            this.RaisePropertyChanged("SelectedMaterial");
            DeleteMaterialCommand.RaiseCanExecuteChanged();
        }
    }
}

Materials and Gauges are both fetched from the RIA Services when the Page loads.

The values display correctly (when they display), and when I make changes to the values the changes stick.  I just can't get them to reliably display.  Any ideas?

Thanks,

-Dan Pingel

Materials and Gauges are both fetched from the RIA Services when the Page loads.The values display correctly (when they display), and when I make changes to the values the changes stick.  I just can't get them to reliably display.  Any ideas?Thanks,-Dan Pingel

4 Answers, 1 is accepted

Sort by
0
Glenn Dawson
Top achievements
Rank 1
answered on 02 Aug 2010, 07:42 PM
I have a similar visibility issue with the GridViewComboBoxColumn. The values are not visible but appear when I click on one of the cells in the column.
0
Pavel Pavlov
Telerik team
answered on 05 Aug 2010, 02:08 PM
Hi guys,
Such behavior typically occurs when there is a problem in the ItemsSource binding of the combo column .

Having a view model as a DataContext of the grid and trying to bind to in generally would not work , as the DataContext of the cell would not be the view model , but the business object related to the row instead.

There are two ways of solving the issue :
1. Expose the view model as a static resource on the page so that it can be easily accessible by the binding .
or

2. Set the ItemsSource of the combo column in code behind instead of binding it in XAML .

If these do not help I would recommend to send me a runnable project so I can step trough it and see what  is causing the issue.

*To be able to attach the zip with the repro project, you may need to open a support ticket.

Best wishes,
Pavel Pavlov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Radoslaw
Top achievements
Rank 1
answered on 03 Feb 2011, 02:57 PM

One more important notice:

 

It is necessary to have the same data types binded to corresponding property: DataMemberBinding and SelectedValueMemberPath; even int32 and int64 cause GridViewComboBoxColumn do not display selected value.

0
Pavel Pavlov
Telerik team
answered on 09 Feb 2011, 10:23 AM
Hi guys ,

Indeed form my experience the most common reason for such erroneous behavior is having the id in the combo source as integer and the matching id in the GridView source as string for example.

The second reason may be  trying to use element name binding.

Kind regards,
Pavel Pavlov
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
GridView
Asked by
Dan Pingel
Top achievements
Rank 1
Answers by
Glenn Dawson
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Radoslaw
Top achievements
Rank 1
Share this question
or