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

GridViewComboBoxColumn and HierarchyChildTemplate

2 Answers 116 Views
GridView
This is a migrated thread and some comments may be shown as answers.
david ocasio
Top achievements
Rank 1
david ocasio asked on 06 Nov 2009, 01:09 PM
Not sure if this is a bug or not 
I suspect it is

I have a Radgrid in a HierarchyChildTemplate with a comboxcolumn

it order to get the Itemssource to the comboboxolumn for the lookup i have hooked the
loaded event of the grid and load the itemsource like so

            <telerikGridView:RadGridView.HierarchyChildTemplate> 
                <DataTemplate> 
                    <telerikGridView:RadGridView ItemsSource="{Binding lstTestClass}" AutoGenerateColumns="False" Loaded="SetUpChildComboBox">  
                        <telerikGridView:RadGridView.Columns > 
                            <telerikGridView:GridViewSelectColumn></telerikGridView:GridViewSelectColumn> 
                            <telerikGridView:GridViewDataColumn DataMemberBinding="{Binding iQty,Mode=TwoWay}" /> 
                            <telerikGridView:GridViewComboBoxColumn UniqueName="ComboCol"  DisplayMemberPath="NameState" SelectedValueMemberPath="IDState" DataMemberBinding="{Binding IDState}" /> 
                        </telerikGridView:RadGridView.Columns> 
                    </telerikGridView:RadGridView> 
                </DataTemplate> 
            </telerikGridView:RadGridView.HierarchyChildTemplate> 
 

    Private Sub SetUpChildComboBox(ByVal sender As ObjectByVal e As System.Windows.RoutedEventArgs)  
        Dim RadGridview As RadGridView = DirectCast(sender, RadGridView)  
        DirectCast(RadGridview.Columns("ComboCol"), GridViewComboBoxColumn).ItemsSource = collStates  
    End Sub 
 

Problem is the initial value of that column is not shown even though it is in the data.

If i click in the cell to edit
The value is already selected (from the combo box)  
and when leaving edit mode is now shown in the cell.

so the questions:

  1. am i hooking the wrong event
  2. is there another/better  way to do it
  3. is it a bug

i have included screenshots of  the problem.

thanks
dco

below find the test project i made to highlight and test the issue.

<UserControl xmlns:telerikGridView="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"  x:Class="agTestBed.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"   
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">  
  <Grid x:Name="LayoutRoot">  
        <telerikGridView:RadGridView x:Name="TestGrid" SelectionMode="Multiple" AutoGenerateColumns="False">  
            <telerikGridView:RadGridView.HierarchyChildTemplate> 
                <DataTemplate> 
                    <telerikGridView:RadGridView ItemsSource="{Binding lstTestClass}" AutoGenerateColumns="False" Loaded="SetUpChildComboBox">  
                        <telerikGridView:RadGridView.Columns > 
                            <telerikGridView:GridViewSelectColumn></telerikGridView:GridViewSelectColumn> 
                            <telerikGridView:GridViewDataColumn DataMemberBinding="{Binding iQty,Mode=TwoWay}" /> 
                            <telerikGridView:GridViewComboBoxColumn UniqueName="ComboCol"  DisplayMemberPath="NameState" SelectedValueMemberPath="IDState" DataMemberBinding="{Binding IDState}" /> 
                        </telerikGridView:RadGridView.Columns> 
                    </telerikGridView:RadGridView> 
                </DataTemplate> 
            </telerikGridView:RadGridView.HierarchyChildTemplate> 
            <telerikGridView:RadGridView.Columns> 
                <telerikGridView:GridViewSelectColumn></telerikGridView:GridViewSelectColumn> 
                <telerikGridView:GridViewDataColumn DataMemberBinding="{Binding iQty,Mode=TwoWay}" ></telerikGridView:GridViewDataColumn> 
                <telerikGridView:GridViewComboBoxColumn UniqueName="ComboCol"  DisplayMemberPath="NameState" SelectedValueMemberPath="IDState" DataMemberBinding="{Binding IDState}" /> 
            </telerikGridView:RadGridView.Columns> 
        </telerikGridView:RadGridView> 
  </Grid> 
</UserControl> 
 
Imports System.Windows.Data  
Imports System.Windows.Ria.Data  
Imports Telerik.Windows.Controls  
Imports Telerik.Windows.Data  
Imports System.ComponentModel  
Imports System.ComponentModel.DataAnnotations  
Imports System.Collections.ObjectModel  
Imports System.Runtime.CompilerServices  
 
Partial Public Class MainPage  
    Inherits UserControl  
 
    Public Sub New()  
        InitializeComponent()  
    End Sub 
 
    Public CollTestclass As New ObservableCollection(Of TestClass)  
    Public collStates As New ObservableCollection(Of State)  
 
    Private Sub MainPage_Loaded(ByVal sender As ObjectByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded  
 
        'create states list data  
        collStates.Add(New State With {.IDState = "0", .NameState = "FL"})  
        collStates.Add(New State With {.IDState = "1", .NameState = "GA"})  
 
        ' create test data  
        CollTestclass.Add(New TestClass With {.iQty = 1, .IDState = "0", .lstTestClass = Makeitup()})  
        CollTestclass.Add(New TestClass With {.iQty = 2, .IDState = "1", .lstTestClass = Makeitup()})  
        CollTestclass.Add(New TestClass With {.iQty = 3, .IDState = "1", .lstTestClass = Makeitup()})  
        CollTestclass.Add(New TestClass With {.iQty = 4, .IDState = "0", .lstTestClass = Makeitup()})  
        CollTestclass.Add(New TestClass With {.iQty = 5, .IDState = "1", .lstTestClass = Makeitup()})  
        CollTestclass.Add(New TestClass With {.iQty = 6, .IDState = "0", .lstTestClass = Makeitup()})  
        CollTestclass.Add(New TestClass With {.iQty = 7, .IDState = "1", .lstTestClass = Makeitup()})  
 
        ' set child table definition  
        Dim detailDefinition As New GridViewTableDefinition()  
        detailDefinition.Relation = New PropertyRelation("lstTestClass")  
        TestGrid.TableDefinition.ChildTableDefinitions.Add(detailDefinition)  
 
        ' set up main grid datasources  
        DirectCast(TestGrid.Columns("ComboCol"), GridViewComboBoxColumn).ItemsSource = collStates  
        TestGrid.ItemsSource = CollTestclass  
    End Sub 
 
    Public Function Makeitup() As ObservableCollection(Of TestClass)  
        Dim CollTestclass As New ObservableCollection(Of TestClass)  
        CollTestclass.Add(New TestClass With {.iQty = 1, .IDState = "0"})  
        CollTestclass.Add(New TestClass With {.iQty = 2, .IDState = "1"})  
        CollTestclass.Add(New TestClass With {.iQty = 3, .IDState = "1"})  
        CollTestclass.Add(New TestClass With {.iQty = 4, .IDState = "0"})  
        CollTestclass.Add(New TestClass With {.iQty = 5, .IDState = "1"})  
        CollTestclass.Add(New TestClass With {.iQty = 6, .IDState = "0"})  
        CollTestclass.Add(New TestClass With {.iQty = 7, .IDState = "1"})  
        Return CollTestclass  
    End Function 
 
    Private Sub SetUpChildComboBox(ByVal sender As ObjectByVal e As System.Windows.RoutedEventArgs)  
        Dim RadGridview As RadGridView = DirectCast(sender, RadGridView)  
        DirectCast(RadGridview.Columns("ComboCol"), GridViewComboBoxColumn).ItemsSource = collStates  
    End Sub 
 
    Private Sub TestGrid_DataLoaded(ByVal sender As ObjectByVal e As System.EventArgs) Handles TestGrid.DataLoaded  
    End Sub 
 
    Private Sub TestGrid_Loaded(ByVal sender As ObjectByVal e As System.Windows.RoutedEventArgs) Handles TestGrid.Loaded  
    End Sub 
End Class 
 
Public Class State  
    <Display(Name:="IDState", Description:="IDState")> _  
    Public Property IDState() As String 
        Get 
            Return _IDState  
        End Get 
        Set(ByVal value As String)  
            _IDState = value  
        End Set 
    End Property 
    Protected _IDState As String 
 
 
    <Display(Name:="NameState", Description:="NameState")> _  
    Public Property NameState() As String 
        Get 
            Return _NameState  
        End Get 
        Set(ByVal value As String)  
            _NameState = value  
        End Set 
    End Property 
    Protected _NameState As String 
 
End Class 
 
Public Class TestClass  
    Implements INotifyPropertyChanged  
 
    Public Event PropertyChanged(ByVal sender As ObjectByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged  
    Private Sub FirePropertyChanged(ByVal [property] As String)  
        If Not String.IsNullOrEmpty([property]) Then 
            RaiseEvent PropertyChanged(MeNew PropertyChangedEventArgs([property]))  
        End If 
    End Sub 
 
    <Display(Name:="iQty", Description:="iQty")> _  
    Public Property iQty() As Integer 
        Get 
            Return _iQty  
        End Get 
        Set(ByVal value As Integer)  
            _iQty = value  
            FirePropertyChanged("iQty")  
        End Set 
    End Property 
    Protected _iQty As Integer 
 
 
    <Display(Name:="IDState", Description:="IDState")> _  
    Public Property IDState() As String 
        Get 
            Return _IDState  
        End Get 
        Set(ByVal value As String)  
            _IDState = value  
            FirePropertyChanged("IDState")  
        End Set 
    End Property 
    Protected _IDState As String 
 
 
    <Display(Name:="lstTestClass", Description:="lstTestClass")> _  
    Public Property lstTestClass() As ObservableCollection(Of TestClass)  
        Get 
            Return _lstTestClass  
        End Get 
        Set(ByVal value As ObservableCollection(Of TestClass))  
            _lstTestClass = value  
            FirePropertyChanged("lstTestClass")  
        End Set 
    End Property 
    Protected _lstTestClass As ObservableCollection(Of TestClass)  
 
End Class 
 

2 Answers, 1 is accepted

Sort by
0
Accepted
Pavel Pavlov
Telerik team
answered on 11 Nov 2009, 01:21 PM
Hello david ocasio,
Thank you for sending such detailed illustration of the bug. It helped me to quickly isolate the problem.
I have updated your Telerik points. The bug will be fixed for the upcoming Q3 ServicePack release.

Meanwhile  I have found a workaround with your code.

To make the combo work - please use the DataLoaded instead of the Loaded event of the nested RadGridView when setting the ItemsSource of the  combo column.

Kind 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.
0
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 12 Nov 2009, 02:58 PM
Interestingly,

you are correct in my test project
changing it to the dataloaded event did work
(after i remembered to change the event signature to eventargs instead of routedeventargs)

but in my big project in did not work .
instead the id started showing up.
i am using your internal builds though so it may be that too

anyway bottom line
i changed the code to use templates instead
embedded a regular combo box
and that works fine

i will wait for the service pack you mentioned to change it back  to the combo column

thanks for your help
dco


Tags
GridView
Asked by
david ocasio
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
Share this question
or