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

treeview in raddopdownbutton

5 Answers 63 Views
TileView
This is a migrated thread and some comments may be shown as answers.
terry
Top achievements
Rank 1
terry asked on 11 Oct 2011, 02:19 AM
I buid a Treeview in a Raddopdownbutton ,How can I bind the Treeview to the Oracle database.

5 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 13 Oct 2011, 08:40 AM
Hello Terry,

 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

Greetings,
Petar Mladenov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
terry
Top achievements
Rank 1
answered on 14 Oct 2011, 06:41 AM
Thank you for your answer .I bind to the oracle database ! But ,I still have problems.
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;
        }
0
terry
Top achievements
Rank 1
answered on 14 Oct 2011, 06:50 AM
The project of mine
0
terry
Top achievements
Rank 1
answered on 17 Oct 2011, 07:38 AM
0
Petar Mladenov
Telerik team
answered on 18 Oct 2011, 02:34 PM
Hello Terry,

 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 >>

Tags
TileView
Asked by
terry
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
terry
Top achievements
Rank 1
Share this question
or