treeview in raddopdownbutton

6 posts, 0 answers
  1. terry
    terry avatar
    4 posts
    Member since:
    Sep 2011

    Posted 10 Oct 2011 Link to this post

    I buid a Treeview in a Raddopdownbutton ,How can I bind the Treeview to the Oracle database.
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 13 Oct 2011 Link to this post

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

  3. DevCraft banner
  4. terry
    terry avatar
    4 posts
    Member since:
    Sep 2011

    Posted 14 Oct 2011 Link to this post

    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;
            }
  5. terry
    terry avatar
    4 posts
    Member since:
    Sep 2011

    Posted 14 Oct 2011 Link to this post

    The project of mine
  6. terry
    terry avatar
    4 posts
    Member since:
    Sep 2011
  7. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 18 Oct 2011 Link to this post

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

Back to Top
DevCraft banner