Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,411 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 2,469 people online right now. Registration is fast and FREE... Join Now!




Populate TreeViews from database

 
Reply to this topicStart new topic

Populate TreeViews from database, C# Help

MutokoCraig
15 Oct, 2008 - 07:32 AM
Post #1

New D.I.C Head
*

Joined: 15 Oct, 2008
Posts: 1

CODE
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Collections;
using System.Data.SqlClient;

namespace Envision
{
    public partial class Envision : Form
    {
        SqlConnection conn = new SqlConnection("Data Source=ICNWS00054;Initial Catalog=EnvisionPlatformDatabase;User ID=sa;Password=3Password5");
        SqlDataAdapter dtd;
        DataSet ds;
        DataView dv;
        public TreeNode node;

        public Envision()
        {
            InitializeComponent();
        }

        //
        private void GetData(int EnCid, TreeNode EnNode)
        {
            dv = ds.Tables[0].DefaultView;
            dv.RowFilter = "EnCid=" + EnCid;
            int dvC = dv.Count;
            if (EnNode == null)
            {
                int i = 0;
                while (i < dvC)
                {
                    dv = ds.Tables[0].DefaultView;
                    dv.RowFilter = "EnCid=" + EnCid;

                    TreeNode node = new TreeNode();
                    node.Text = dv[i]["EnNode"].ToString();
                    node.Tag = int.Parse(dv[i]["NodeId"].ToString());
                    
                    this.treeView1.Nodes.Add(node);
                  
                    GetData((int)node.Tag, node);
                    i++;
                }
            }
            else
            {
                int i = 0;
                while (i < dvC)
                {
                    dv = ds.Tables[0].DefaultView;
                    dv.RowFilter = "EnCid=" + EnCid;

                    TreeNode node = new TreeNode();
                    node.Text = dv[i]["EnNode"].ToString();
                    node.Tag = int.Parse(dv[i]["NodeId"].ToString());

                    EnNode.Nodes.Add(node);

                    GetData(int.Parse(dv[i]["NodeId"].ToString()), node);
                    i++;
                }
            }
        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            ArrayList EnvisionP = new ArrayList();
            TreeNode EnNode = new TreeNode("EnNode");
            EnNode.Tag = EnvisionP;

            dtd = new SqlDataAdapter("select * from [User Panel] order by NodeId", conn);
            ds = new DataSet();
            dtd.Fill(ds, "User Panel");
            GetData(0, null);

        }



        private void ultraExplorerBar1_ItemClick(object sender, Infragistics.Win.UltraWinExplorerBar.ItemEventArgs e)
        {
            
        }

        private void treeView1_AfterSelect_1(object sender, TreeViewEventArgs e)
        {
        
        }
        private void treeView2_AfterSelect(object sender, TreeViewEventArgs e)
        {  

        }

        private void ultraListView1_ItemActivated(object sender, Infragistics.Win.UltraWinListView.ItemActivatedEventArgs e)
        {

        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
          
        }

    }
}






Hi I am trying to make three treeviews to populate from the same database but using diffrent tables for each tree view.



Can Some One Help Me

Mod edit - Please code.gif
~BetaWar
User is offlineProfile CardPM
+Quote Post

wingot
RE: Populate TreeViews From Database
15 Oct, 2008 - 07:34 AM
Post #2

New D.I.C Head
*

Joined: 13 Oct, 2008
Posts: 38

Just a recommendation. Putting the code within a code box (as the rules state) will make it all much easier to read and you are more likely to receive a legitimate response.

I'll take a look at the code, just a minute.

EDIT: Ok, from what I can tell (and you code really isn't clear when I'm trying to read it) it looks like your database and table selection criteria is all hard coded into the GetData method. If you are wanting to populate from three different tables and views, these will need to be parameters to that method, not hard coded.

Also, so far as I can see, you are only creating one treenode and no treeviews, so the first thing you'll need to do is create three treeviews in order to populate them.

Finally, it would help if you explain what you've done so far, any solutions you've tried, and your code. It would also help if you could be more descriptive with your question statement, although from what I can gather the fact that everything is hard coded is the problem that you have defined.

This post has been edited by wingot: 15 Oct, 2008 - 07:42 AM
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Populate TreeViews From Database
15 Oct, 2008 - 01:38 PM
Post #3

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,939



Thanked: 42 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
Topic renamed to be more descriptive of the problem.
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 12:21PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month