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

[Solved] Treeview Binding from WCF

1 Answer 125 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
al
Top achievements
Rank 1
al asked on 15 Apr 2009, 08:00 AM
Can anyone helped me here.
I am using treeview for silverlight. and i am trying to pass values to it. the structure of the data comming from the WCF is shown below

[

DataContract]

 

 

public class QPQuestionSummary

 

{

string _LessonObjectiveTitle = "";

 

List<QuestionSummary> _QuestionTitle = new List<QuestionSummary>();

 

[

DataMember]

 

public string LessonObjectiveTitle

{

get { return _LessonObjectiveTitle; }

 

set { _LessonObjectiveTitle = value; }

}

[

DataMember]

 

public List<QuestionSummary> QuestionTitle

{

 

get { return _QuestionTitle; }

 

set { _QuestionTitle = value; }

}

}

[

DataContract]

 

 

 

public class QuestionSummary

 

{

 

public QuestionSummary(String Question_Title)

 

 

 {

QuestionTitle = Question_Title;

}

 

 

public QuestionSummary()

{

}

[

DataMember]  

 

 

public string QuestionTitle

{

 

get;

 

 

 

set;

 

 

 }

}

 

 

public List<QPQuestionSummary> QuestionPoolSummary(int StatSlidId, string ConnectionString)
{        

List

 

<QPQuestionSummary> _Summary = new List<QPQuestionSummary>();
//some codes here
return _Summary
}

The data template for the Treeview is show below
<UserControl.Resources>  

 

 

<telerik:HierarchicalDataTemplate x:Key="QuestionSummary" ItemsSource="{Binding ItemsSelected}">

 

 

<TextBlock Text="{Binding QuestionName}" Foreground="Green" FontStyle="Italic" />

 

 

</telerik:HierarchicalDataTemplate>

 

 

</UserControl.Resources>

 

 

<Grid x:Name="LayoutRoot" Background="White">

 

 

<telerikNavigation:RadTreeView Margin="8,8,64,8" x:Name="tSummary"

 

ItemTemplate="{StaticResource QuestionSummary}">

 

 

</telerikNavigation:RadTreeView>

 

 

</Grid>

and the class in the silverlight to catch the data is shown below

 

public

 

class SummaryQuestions

 

 

 

 

 

 

 

{

 

 

public SummaryQuestions(string Name)

 

{

QuestionName = Name;

ItemsSelected =

 

new List<SummaryItems>();

 

}

 

 

public string QuestionName

 

{

 

 

get;

 

 

 

set;

 

}

 

 

public List<SummaryItems> ItemsSelected

 

{

 

 

get;

 

 

 

set;

 

}

}

 

 

public class SummaryItems

 

 

 

 

 

{

 

 

public SummaryItems(string Name)

 

{

ItemName = Name;

}

 

 

public string ItemName

 

{

 

 

get;

 

 

 

set;

 

}

}

 

 

public class SummaryQuestionList : List<SummaryQuestions>

 

{

 

 

public SummaryQuestionList()

 

{

 

 

App _app = (App)Application.Current;

 

QPQuestions.

 

QPQuestionsClient _Summary = new QuestionPoolSL.QPQuestions.QPQuestionsClient();

 

_Summary.QuestionPoolSummaryAsync(_app.StatSlideID(), _app.ConnectionString());

_Summary.QuestionPoolSummaryCompleted +=

 

new EventHandler<QuestionPoolSL.QPQuestions.QuestionPoolSummaryCompletedEventArgs>(Summary_QuestionPoolSummaryCompleted);

 

}

 

 

protected void Summary_QuestionPoolSummaryCompleted(object sender, QuestionPoolSL.QPQuestions.QuestionPoolSummaryCompletedEventArgs e)

 

{

 

 

SummaryQuestions y;

 

 

 

foreach (QPQuestionSummary x in e.Result)

 

{

Add(y =

 

new SummaryQuestions(x.LessonObjectiveTitle));

 

y.ItemsSelected.Add(

 

new SummaryItems(x.QuestionTitle[0].QuestionTitle));

 

}

}

}

and in the load part of the page i try to do this.

try

 

 

{

 

tSummary.ItemsSource =

 

new SummaryQuestionList();

}

catch (Exception ex)

{

MessageBox.Show(ex.Message, "Error!", MessageBoxButton.OK);

}

but there are no items displayed....

the treeview control is not that friendly to use. can you make a documentation how to use it. I mean a detailed one.

Thaks a lot....

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Ivan
Telerik team
answered on 15 Apr 2009, 04:06 PM
Hello al,

Please preview the How to bind RadTreeView to hierarchical data and use load-on-demand article where binding to the data service is in depth demonstrated.

For you convenience I have attached the same example but with new RadControls assemblies in it.

Best wishes,
Ivan
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
TreeView
Asked by
al
Top achievements
Rank 1
Answers by
Ivan
Telerik team
Share this question
or