DataTableTreeExample.cs :  » GUI » TreeViewAdv » SampleApp » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GUI » TreeViewAdv 
TreeViewAdv » SampleApp » DataTableTreeExample.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Aga.Controls.Tree;
using Aga.Controls.Tree.NodeControls;
namespace SampleApp{
    public partial class DataTableTreeExample : UserControl
    {

        private DataTableTreeModel m_dataTableModel;
        public DataTableTreeExample()
        {
            InitializeComponent();
            DataTable table = CreateSampleDataTable();

            this.dataGridView1.Columns.Clear();
            this.dataGridView1.DataSource = table;

            treeViewAdv1.LoadOnDemand = true;
            treeViewAdv1.SelectionMode = TreeSelectionMode.Multi;
            treeViewAdv1.NodeControls.Clear();

            NodeStateIcon ni = new NodeStateIcon();
            ni.DataPropertyName = "Icon";
            treeViewAdv1.NodeControls.Add(ni);

            NodeTextBox tb = new NodeTextBox();
            tb.DataPropertyName = "Text";
            treeViewAdv1.NodeControls.Add(tb);

            
            m_dataTableModel = new DataTableTreeModel(table,"id");
            this.treeViewAdv1.Model = m_dataTableModel;
            this.treeViewAdv1.SelectionChanged += new EventHandler(treeViewAdv1_SelectionChanged);
        }

        void treeViewAdv1_SelectionChanged(object sender, EventArgs e)
        {
            Enabling();                        
            //treeViewAdv1.SelectedNodes
        }

        private void Enabling()
        {
            if (treeViewAdv1.SelectedNodes.Count == 0)
                addNodeToolStripMenuItem.Enabled = false;
            else
            addNodeToolStripMenuItem.Enabled = !treeViewAdv1.SelectedNode.IsLeaf;
        }


        private static DataTable CreateSampleDataTable()
        {
            DataTable table = new DataTable();
            table.Columns.Add("ID", typeof(int));
            table.Columns.Add("ParentID", typeof(int));
            table.Columns.Add("IsFolder", typeof(bool));
            table.Columns.Add("Name");
            table.Columns.Add("Tag");

            table.Rows.Add(1, 1, true, "Columbia River ", "set ID = ParentID for root");
            table.Rows.Add(2, 1, false, "John Day", " ");
            table.Rows.Add(3, 1, true, "Snake River", "");
            table.Rows.Add(4, 3, false, "Payette River", "");
            table.Rows.Add(5, 3, false, "Boise River", "");

            return table;
        }

        private void addNode_Click(object sender, 
            EventArgs e)
        {
            if (treeViewAdv1.SelectedNode != null)
            {
                 DataRowNode n = treeViewAdv1.SelectedNode.Tag as DataRowNode;
                 if (!Convert.ToBoolean(n.Row["IsFolder"]))
                 {
                     return;
                 }

             TreePath parent = treeViewAdv1.GetPath(treeViewAdv1.SelectedNode);

             m_dataTableModel.AddChild(parent, "Hi "+DateTime.Today.ToShortDateString());
                
            }
        }

        private void renameToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
        {
            Console.WriteLine("Row added");
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.