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

Unable to assign ItemsSource property to GridView in CodeBehind

5 Answers 176 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Syed Nadeem
Top achievements
Rank 1
Syed Nadeem asked on 22 Apr 2010, 07:51 AM

Hi,

I have TabControlcalled mainTabs with a TabItem called CurrentTasks. In the CurrentTasks TabItem I show a GridView(say RadGridView1)  with a list of tasks which works fine. This GridViewis populated in code behind with an ObservableCollection.

As per the logic, eachtask in the RadGridView1 has some dependent tasks called PredecessorsTasks(tasks that were completed before the selected task was assigned) andSuccessor Tasks(tasks assigned to other users which are depending on thecurrent task to be completed by the current user).

Now, I want to makethe rows of this RadGridView1 expandable so that I can show thedetails of selected Task in two tabs as Predecessor Tab and Successor Tab. Eachof these tabs would have a GridView(say InnerRadGridView1 andInnerRadGridView2) showing a list of tasks respectively.

I am trying to assignthe ItemsSource Property for  InnerRadGridView1 programatically to anObservableCollection in the code behind. The problem is that it does not showany intellisence for me to access the InnerRadGridView1 (for eg. Iwant to assign it as   InnerRadGridView1 .ItemsSource = Tasks;where Tasks is my ObservableCollection). 

Pleaseprovide me a solution to this issue. Im really stuck.

I am also attaching ascreenshot of what exactly the navigation flow of my application is.

5 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 22 Apr 2010, 07:57 AM
Hi Syed,

Why not use InnerRadGridView1 Loaded event (attached in xaml) to assign ItemsSource for this grid? Sender argument of the event is the grid itself.

Best wishes,
Vlad
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
Syed Nadeem
Top achievements
Rank 1
answered on 22 Apr 2010, 08:15 AM
Hi Vlad,

I'm a complete newbie to Telerik. Could you send me a sample application which suits the flow? I hope that would help me better.

Cheers,
Syed Nadeem.
0
Accepted
Vlad
Telerik team
answered on 22 Apr 2010, 08:16 AM
Hi Syed,

All you need is to declare this event (Loaded) in XAML for desired grid and in the code behind cast sender argument to RadGridView and assign ItemsSource.

Greetings,
Vlad
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
Syed Nadeem
Top achievements
Rank 1
answered on 22 Apr 2010, 10:54 AM
Hi Vlad,

I have done as you suggested, by specifying the Loaded method in the XAML code and in the code behind too. But when I run the code, the expansion doesnt happen, thereby not loading the Tabs. Nor is the Loaded method hit in debuggging mode.

XAML code
<!- This is the part of code from the Outer GridView's RowDetails Template->
<grid:RadGridView.RowDetailsTemplate>
    <DataTemplate>
        <navigation:RadTabControl BackgroundVisibility="Collapsed" x:Name="RadTabControl1" Width="900" Margin="10" VerticalAlignment="Center" Background="Transparent" controls:StyleManager.Theme="Office_Black">

            <navigation:RadTabItem Header="Predecessors" Height="24" Foreground="Black">
                <Border BorderBrush="#FF848484" BorderThickness="0,1,0,0">
                    
                    <grid:RadGridView x:Name="PredecessorGridView"
                                                      
                                                      Height="300" 
                                                      RowIndicatorVisibility="Collapsed" 
                                                      AutoGenerateColumns="False" 
                                                      Loaded="PredecessorsGridView_Loaded"
 CanUserFreezeColumns="False" 
                                                      BorderThickness="0" 
                                                      CanUserResizeColumns="False"
 ShowGroupPanel="False" 
                                                      dragdrop:RadDragAndDropManager.AllowDrag="False"  
 Margin="0" 
 Width="900">

                        <grid:RadGridView.Columns>
                            <grid:GridViewDataColumn  DataMemberBinding="{Binding Game}" Header="Game"></grid:GridViewDataColumn>
                            <grid:GridViewDataColumn DataMemberBinding="{Binding Name}" Header="Task"></grid:GridViewDataColumn>
                            <grid:GridViewDataColumn DataMemberBinding="{Binding DueDate}" Header="Due Date"></grid:GridViewDataColumn>
                            <grid:GridViewDataColumn DataMemberBinding="{Binding Status}" Header="Status"></grid:GridViewDataColumn>
                            <grid:GridViewDataColumn DataMemberBinding="{Binding Priority}" Header="Priority"></grid:GridViewDataColumn>
                        </grid:RadGridView.Columns>
                    </grid:RadGridView>
                </Border>
            </navigation:RadTabItem>


        </navigation:RadTabControl>
    </DataTemplate>
</grid:RadGridView.RowDetailsTemplate>



XAML.cs Code

        private void InnerRadGridView_Loaded(RadGridView sender, RoutedEventArgs e)
        {
                    TaskInfo t1 = OuterRadGridView.SelectedItem as TaskInfo;
                     
                         webSerciveClient.AllDependantTasksCompleted += new EventHandler<EngineerView.TaskManagerServiceReference.AllDependentTasksCompletedEventArgs>(Populate_PredecessorGrid);
                    webSerciveClient.AllDependantTasksAsync(currentUserId, t1.TaskId );

                    //dependentTasks is a ObservableCollection which is populated in the handler function 'Populate_PredecessorGrid'
                    sender.ItemsSource = dependentTasks;   
        }


Any clues?

Cheers,
Syed.

0
Syed Nadeem
Top achievements
Rank 1
answered on 22 Apr 2010, 01:38 PM
Thanks Vlad!

I got this issue fixed.

Cheers,
Syed Nadeem.


Tags
GridView
Asked by
Syed Nadeem
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Syed Nadeem
Top achievements
Rank 1
Share this question
or