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

Combobox in PanelBarItem with different datacontext

1 Answer 107 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
emw1909
Top achievements
Rank 1
emw1909 asked on 03 Jun 2009, 05:14 AM
Please Help, 

I have a radpanelbar that has one radpanelbaritem in it with an Itemtemplate.  the itemtemplate has various control in it.  I databind the radpanelbaritem to a list by setting the datacontext to the list.  the binding for the controls in the template works.  However I have a seperate combobox in the itemtemplate that needs to be bound to a seperate list.  When I try binding it, everything goes thru without errors, but no items show in the combobox.

here is the Xaml:

<

 

telerikNavigation:RadPanelBar x:Name="MLSListing" ExpandMode="Multiple">

 

 

 

<telerikNavigation:RadPanelBarItem IsExpanded="True" ItemsSource="{Binding}">

 

 

 

<telerikNavigation:RadPanelBarItem.ItemTemplate>

 

 

 

<DataTemplate>

 

 

 

<StackPanel Orientation="Horizontal" Margin="5,2,0,0">

 

 

 

<Image x:Name="RemMLSBtn" Source="Images/Cancel.png" Margin="0,0,10,0"></Image>

 

 

 

<TextBlock Text="Agent" Margin="0,3,0,0"></TextBlock>

 

 

 

<telerikInput:RadComboBox x:Name="cmbAgents" Width="100" Height="20" ItemsSource="{Binding}" DisplayMemberPath="FullName" IsEditable="True" IsReadOnly="True" SelectedIndex="0"></telerikInput:RadComboBox>

 

 

 

<TextBlock Text="MLS#" Margin="0,3,0,0"></TextBlock>

 

 

 

<TextBox Text="{Binding MLSNumber, Mode=TwoWay}" Width="70" Margin="5,0,10,0"/>

 

 

 

<TextBlock Text="Price" Margin="0,3,0,0"></TextBlock>

 

 

 

<TextBox x:Name="Price" Width="75" Text="{Binding Amount, Mode=TwoWay}"/>

 

 

 

<TextBlock Text="Date" Margin="0,3,0,0"></TextBlock>

 

 

 

<telerikInput:RadDatePicker Height="20" x:Name="OrgSaleDate" SelectedDate="{Binding Date, Mode=TwoWay}" Width="100" Margin="5,0,10,0"></telerikInput:RadDatePicker>

 

 

 

<TextBlock Text="MLS Status" Margin="0,3,0,0"></TextBlock>

 

 

 

<telerikInput:RadComboBox x:Name="cmbMLSStatus" Width="100" Height="22" IsEditable="True" SelectedIndex="-1" DisplayMemberPath="MLSStatus" ItemsSource="{Binding}" Margin="5,0,10,0"/>

 

 

 

<CheckBox x:Name="REOSale" Content="REO Sale" DataContext="{Binding REOSale, Mode=TwoWay}" Margin="5,0,0,0"/>

 

 

 

</StackPanel>

 

 

 

</DataTemplate>

 

 

 

</telerikNavigation:RadPanelBarItem.ItemTemplate>

 

 

 

<telerikNavigation:RadPanelBarItem.Header>

 

 

 

<StackPanel Orientation="Horizontal" >

 

 

 

<Image x:Name="AddMLSBtn" Source="Images/Addnew.png" Width="24" Height="24" />

 

 

 

<TextBlock Text="MLS Listings" Margin="4,0,0,0" VerticalAlignment="Center" />

 

 

 

</StackPanel>

 

 

 

</telerikNavigation:RadPanelBarItem.Header>

 

 

 

</telerikNavigation:RadPanelBarItem>

 

 

 

</telerikNavigation:RadPanelBar>

Here is the codebehind that sets the datacontext of the radpanelbaritem and the combobox within the itemtemplate.

 

MLSListing.Items(0).dataContext = FRSingle.Listings

 

For i As Integer = 0 To MLSListing.Items.Count - 1

 

 

    Dim RPI As RadPanelBarItem = MLSListing.ItemContainerGenerator.ContainerFromIndex(i)

 

 

    Dim SP As StackPanel = RPI.ItemTemplate.LoadContent

 

 

    Dim ComboList As List(Of RadComboBox) = SP.ChildrenOfType(Of RadComboBox)()

 

 

    For isp As Integer = 0 To ComboList.Count - 1

 

 

        If ComboList.Item(isp).Name = "cmbAgents" Then

 

 

 

 

            ComboList.Item(isp).DataContext = Agents

 

        End If

 

 

 

 

 

    Next

 

 

 

 

 

Next

 

 

 



What am I doing wrong??

1 Answer, 1 is accepted

Sort by
0
Valeri Hristov
Telerik team
answered on 03 Jun 2009, 11:11 AM
Hello Eric,

I already answered your support ticket, in case anyone has the same problem I am posting the same text:
The problem is that when you call the LoadContent() method of the DataTemplate, new instances of the controls in the template are created, that are not the same as the controls, displayed in the panel bar. To avoid the problem I would recommend instead of calling:
Dim
ComboList As List(Of RadComboBox) = SP.ChildrenOfType(Of RadComboBox)()

To call
Dim
ComboList As List(Of RadComboBox) = RPI.ChildrenOfType(Of RadComboBox)()

Which will find the real RadComboBox controls in the RadPanelBarItem.

Greetings,
Valeri Hristov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
PanelBar
Asked by
emw1909
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
Share this question
or