Hi,
I am trying to replicate the RadGridView on http://demos.telerik.com/silverlight/#GridView/FirstLook where I have a GridView and within a RadTabItem I want to have another GridView based on the expanded row's Id I run another query and populate the Inner GridView. The issue is firstly I am unable to assign the ItemsSource property of the Inner GridView which is placed on the RadTabItem from the code behind.
I am in urgent need of solving this issue. Any help will be highly appreciated.
Please find the code for the xaml and xaml.cs below.
XAML CODE:
<UserControl xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" xmlns:basics="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" x:Class="EngineerView.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:grid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
xmlns:controls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"
xmlns:gridParts="clr-namespace:Telerik.Windows.Controls.GridView;assembly=Telerik.Windows.Controls.GridView"
xmlns:gridView="clr-namespace:Telerik.Windows.Controls.GridView;assembly=Telerik.Windows.Controls.GridView"
xmlns:dragdrop="clr-namespace:Telerik.Windows.Controls.DragDrop;assembly=Telerik.Windows.Controls"
xmlns:telerikData="clr-namespace:Telerik.Windows.Data;assembly=Telerik.Windows.Data"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:panels="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"
xmlns:primitives="clr-namespace:Telerik.Windows.Controls.Primitives;assembly=Telerik.Windows.Controls"
xmlns:dragDrop="clr-namespace:Telerik.Windows.Controls.DragDrop;assembly=Telerik.Windows.Controls"
xmlns:telerikNavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"
xmlns:navigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"
mc:Ignorable="d" d:DesignWidth="1113" d:DesignHeight="557" >
<UserControl.Resources>
<DataTemplate x:Key="ApplicationDragTemplate">
<Image Source="{Binding IconPath}" Stretch="None" VerticalAlignment="Top" />
</DataTemplate>
<Style TargetType="ListBoxItem" x:Key="draggableItemStyle">
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="dragDrop:RadDragAndDropManager.AllowDrag" Value="True" />
</Style>
</UserControl.Resources>
<basics:TabControl Name="mainTabs" >
<basics:TabItem Header="Current">
<Grid Name="taskGrid" Margin="0,0,-12,-37" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.737*" />
<ColumnDefinition Width="0.263*" ></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions >
<RowDefinition Height="23"></RowDefinition>
<RowDefinition Height="350"></RowDefinition>
<RowDefinition Height="75"></RowDefinition>
<RowDefinition Height="23"></RowDefinition>
<RowDefinition Height="350"></RowDefinition>
</Grid.RowDefinitions>
<Border Height="30" VerticalAlignment="Top" Grid.Row="0" Grid.Column="0" Margin="0,-7,146,0" Width="812">
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF4B4B4B" />
<GradientStop Color="#FFB5B5C1" Offset="1" />
<GradientStop Color="#FF3F4E6C" Offset="0.394" />
<GradientStop Color="#FF4B4B4B" Offset="0.417" />
</LinearGradientBrush>
</Border.Background>
<Grid >
<Grid.ColumnDefinitions >
<ColumnDefinition Width="2*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="To Do:" Margin="0,5,-10,5" Foreground="#FFFFFFFF" FontSize="12" HorizontalAlignment="Right" Width="812" />
</Grid>
</Border>
<grid:RadGridView x:Name="RadGridView1"
Foreground="Black"
ScrollViewer.HorizontalScrollBarVisibility="Visible"
ScrollViewer.VerticalScrollBarVisibility="Visible"
dragdrop:RadDragAndDropManager.AllowDrag="True"
HorizontalAlignment="Left"
BorderThickness="1,0,1,1"
VerticalAlignment="Top"
Background="#FFCDCDCD"
SelectionMode="Extended"
ShowColumnFooters="True"
ShowGroupFooters="True"
MinColumnWidth="40"
SelectionChanged="RadGridView1_SelectionChanged"
AutoGenerateColumns="False"
Grid.Row="1"
Grid.Column="0"
Height="auto"
IsReadOnly="True"
Width="797"
RowLoaded="RadGridView1_RowLoaded"
RowIndicatorVisibility="Collapsed"
DataLoadMode="Asynchronous">
<grid:RadGridView.Columns>
<grid:GridViewToggleRowDetailsColumn />
<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.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"
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>
</grid:RadGridView>
</basics:TabControl>
</UserControl>
XAML.CS code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls.DragDrop;
using System.Collections.ObjectModel;
using System.Windows.Browser;
using System.Windows.Threading;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;
using System.Collections;
using Telerik.Windows.Controls.TreeView;
using System.Globalization;
using System.Text;
using System.Windows.Data;
using System.Windows.Media.Imaging;
using Telerik.Windows.Data;
using Telerik.Windows.QuickStart;
using System.ComponentModel;
namespace EngineerView
{
public partial class MainPage : UserControl
{
string currentUserId = "";
string currentToDoSort = "";
string currentWorkspaceSort = "";
Brush gridViewDragPossible = new SolidColorBrush(Colors.Orange);
TaskManagerServiceReference.TaskManagerServiceSoapClient tmsClient = new EngineerView.TaskManagerServiceReference.TaskManagerServiceSoapClient();
ObservableCollection<TaskInfo> notStartedTasks = new ObservableCollection<TaskInfo>();
ObservableCollection<TaskInfo> startedTasks = new ObservableCollection<TaskInfo>();
ObservableCollection<TaskInfo> completedTasks = new ObservableCollection<TaskInfo>();
ObservableCollection<TaskInfo> dependantTasks = new ObservableCollection<TaskInfo>();
int currentTaskId = 0;
public MainPage()
{
InitializeComponent();
currentUserId = "1";
PopulateToDo("");
PopulateWorkspace("");
}
public void PopulateToDo(string order)
{
tmsClient.AllAssignedTasksCompleted += new EventHandler<EngineerView.TaskManagerServiceReference.AllAssignedTasksCompletedEventArgs>(NotStartedTasks_Completed);
tmsClient.AllAssignedTasksAsync(int.Parse(currentUserId), "", order);
}
private void PredecessorsGridView_Loaded(object sender, RoutedEventArgs e)
{
RadGridView gridView = (RadGridView)sender;
try
{
TaskInfo t1 = gridView.SelectedItem as TaskInfo;
tmsClient.AllDependantTasksCompleted += new EventHandler<EngineerView.TaskManagerServiceReference.AllDependantTasksCompletedEventArgs>(Populate_PredecessorGrid);
tmsClient.AllDependantTasksAsync("predecessor", int.Parse(currentUserId), int.Parse(t1.TaskId));
}
catch (Exception ex)
{
DisplayError(ex.Message);
}
//GridViewDataColumn column = (GridViewDataColumn)gridView.Columns[4];
//if (column.DataMemberBinding == null)
//{
// Binding binding = new Binding(".");
// binding.Converter = new FuncValueConverter(GetOrderAmount);
// column.DataMemberBinding = binding;
//}
}
void Populate_PredecessorGrid(object sender, EngineerView.TaskManagerServiceReference.AllDependantTasksCompletedEventArgs e)
{
try
{
dependantTasks.Clear();
TaskManagerServiceReference.Task[] l = e.Result;
if (e.Result != null)
{
foreach (TaskManagerServiceReference.Task ts in l)
{
TaskInfo t = new TaskInfo();
t.TaskId = ts.TaskId.ToString();
t.GameId = ts.GameId.ToString();
t.Comments = ts.Comment;
t.DueDate = ts.ProjectedFinish.ToString();
t.StartDate = ts.ActualStart.ToString();
t.Status = ts.Status;
t.Name = ts.Name;
t.Description = ts.Description;
t.Version = ts.Version;
t.Platform = ts.Platform;
t.Game = ts.Game;
t.PercentageComplete = ts.PercentComplete.ToString();
t.Priority = ts.Priority.ToString();
t.FinishDate = ts.ActualFinish.ToString();
t.ProjectedStartDate = ts.ProjectedStart.ToString();
foreach (TaskManagerServiceReference.TaskComment tc in ts.Comments)
t.TaskComments.Add(tc);
if ((ts.AssetName == null) || (ts.AssetName == ""))
{
t.IconPath = "atom.png";
}
dependantTasks.Add(t);
}
}
RadGridView2.ItemsSource = startedTasks;
RadGridView2.UpdateLayout();
lstCompletedTasks.ItemsSource = completedTasks;
}
catch (Exception ex)
{
DisplayError(ex.Message);
}
}
void NotStartedTasks_Completed(object sender, EngineerView.TaskManagerServiceReference.AllAssignedTasksCompletedEventArgs e)
{
try
{
notStartedTasks.Clear();
RadGridView1.ItemsSource = null;
//ObservableCollection<TaskManagerServiceReference.Task> l = e.Result;
TaskManagerServiceReference.Task[] l = e.Result;
if (e.Result != null)
{
foreach (TaskManagerServiceReference.Task ts in l)
{
TaskInfo t = new TaskInfo();
t.TaskId = ts.TaskId.ToString();
t.GameId = ts.GameId.ToString();
t.Comments = ts.Comment;
t.DueDate = ts.ProjectedFinish.ToString();
t.StartDate = ts.ActualStart.ToString();
t.Status = ts.Status;
t.Name = ts.Name;
t.Description = ts.Description;
t.Version = ts.Version;
t.Platform = ts.Platform;
t.Game = ts.Game;
t.PercentageComplete = ts.PercentComplete.ToString();
t.Priority = ts.Priority.ToString();
foreach (TaskManagerServiceReference.TaskComment tc in ts.Comments)
t.TaskComments.Add(tc);
if ((ts.AssetName == null) || (ts.AssetName == ""))
t.IconPath = "atom.png"; //@"http://localhost:50080/images/atom.png";
if (ts.Status == "NOT_STARTED")
notStartedTasks.Add(t);
}
}
RadGridView1.ItemsSource = notStartedTasks;
RadGridView1.UpdateLayout();
}
catch (Exception ex)
{
DisplayError(ex.Message);
}
}
private void RadGridView1_SelectionChanged(object sender, SelectionChangeEventArgs e)
{
btnComplete.Visibility = Visibility.Collapsed;
RadGridView1.Focus();
// TODO: Add event handler implementation here.
try
{
if (e.AddedItems.Count > 0)
{
TaskInfo t = e.AddedItems[0] as TaskInfo;
txtPercentageComplete.IsReadOnly = true;
PopulateCurrentTaskInfo(t);
}
}
catch (Exception ex)
{
DisplayError(ex.Message);
}
}
//Changing name from myWorkspaceBox to RadGridView2
private void RadGridView2_SelectionChanged(object sender, SelectionChangeEventArgs e)
{
btnComplete.Visibility = Visibility.Visible;
RadGridView2.Focus();
try
{
if (e.AddedItems.Count > 0)
{
TaskInfo t = e.AddedItems[0] as TaskInfo;//l[box.SelectedIndex];
txtPercentageComplete.IsReadOnly = false;
PopulateCurrentTaskInfo(t);
}
}
catch (Exception ex)
{
DisplayError(ex.Message);
}
}
//Check if we really need this
private void RadGridView1_RowLoaded(object sender, RowLoadedEventArgs e)
{
//GridViewRow row = e.Row as GridViewRow;
//TaskInfo emp = e.DataElement as TaskInfo;
//if (row != null)
//{
// TaskInfo tline = row.DataContext as TaskInfo;
// if (row != null && tline != null)
// {
// row.IsExpandable = true;
// }
// else
// {
// row.IsExpandable = false;
// }
//}
}
}
}