5 Answers, 1 is accepted
You can use WCF Ria Services in order to bind the RadTreeView to database tables.Examining this documentation article which shows how to achieve this will be a good starting points. Now you have to use some kind of provider se to connect to Oracle database. Please check out this forum post and its useful links at the end:
Sample Entity Framework Provider for Oracle
Ado.Net data Providers
Petar Mladenov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
I reference to the http://www.telerik.com/support/kb/silverlight/general/populating-treeview.aspx
1.Error in the xaml
"[Async_ExceptionOccurred]"
<UserControl.Resources>
<local:HierarchicalDataSource x:Key="Source1" />
<core:HierarchicalDataTemplate x:Key="NodeTemplate" ItemsSource="{Binding Children}">
<TextBlock Text="{Binding NodeText}" Width="400"/>
</core:HierarchicalDataTemplate>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<telerik:RadDropDownButton Name="RadDropDownTree" Height="24" Margin="0,0,0,0" Width="300" Content="全部">
<telerik:RadDropDownButton.DropDownContent>
<telerik:RadTreeView
Name="aa"
HorizontalAlignment="Left"
VerticalAlignment="Top"
ItemsSource="{Binding Source={StaticResource Source1}}"
ItemTemplate="{StaticResource NodeTemplate}"
ItemClick="RadTreeView_ItemClick"/>
</telerik:RadDropDownButton.DropDownContent>
</telerik:RadDropDownButton><telerik:RadButton Height="20" Width="30" Name="bb"/>
2..cs
namespace TreeViewDataBase
{
public class HierarchicalDataSource : ObservableCollection<TableItem>
{
// This list holds all the items that come from the web service result
private List<TableItem> unsortedList = new List<TableItem>();
public HierarchicalDataSource()
{
// Create a new instance of the web service and get the data from the table
DataServiceClient webService = new DataServiceClient();
webService.GetTVSerieCompleted += new EventHandler<GetTVSerieCompletedEventArgs>(WebService_GetTableCompleted);
webService.GetTVSerieAsync();
}
private void WebService_GetTableCompleted(object sender, GetTVSerieCompletedEventArgs e)
{
// transfer all the items from the result to the unsorted list
foreach (TableItem item in e.Result)
{
this.unsortedList.Add(item);
}
// Get all the first level nodes. In our case it is only one - House M.D.
var rootNodes = this.unsortedList.Where(x => x.ParentID == x.NodeID);
// Foreach root node, get all its children and add the node to the HierarchicalDataSource.
// see bellow how the FindChildren method works
foreach (TableItem node in rootNodes)
{
this.FindChildren(node);
this.Add(node);
}
}
private void FindChildren(TableItem item)
{
// find all the children of the item
var children = unsortedList.Where(x => x.ParentID == item.NodeID && x.NodeID != item.NodeID);
// add the child to the item's children collection and call the FindChildren recursively, in case the child has children
foreach (TableItem child in children)
{
item.Children.Add(child);
FindChildren(child);
}
}
}
}
3.Connect to the database
[OperationContract]
public List<TableItem> GetTVSerie()
{
List<TableItem> returnlist1 = new List<TableItem>();
//创建连接
String oracleConnString = "Data Source=APTS;User Id=terry;Password=terry123;";
OracleConnection oracleCon = new OracleConnection(oracleConnString);
oracleCon.Open();
string orclSql = "select * from company";
OracleCommand cmm = new OracleCommand(orclSql, oracleCon);
OracleDataAdapter oda = new OracleDataAdapter(cmm);
DataSet ds = new DataSet();
oda.Fill(ds, "company");
foreach (DataRow dr in ds.Tables["company"].Rows)
{
returnlist1.Add(new TableItem(Convert.ToString(dr["nodetext"]), Convert.ToInt32(dr["nodeid"]), Convert.ToInt32(dr["parentid"])));
}
return returnlist1;
}
Example in the website can't run rightly.
The project from the mentioned post is outdated - from 2008 and it is designed for Silverlight 3, probably this could be problematic. Have you considered using this article instead as a guidance?
Kind regards,Petar Mladenov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>