Click here to Skip to main content
16,012,468 members
Home / Discussions / C#
   

C#

 
QuestionProject Pin
mrithula811-Feb-09 20:32
mrithula811-Feb-09 20:32 
AnswerRe: Project Pin
Rob Philpott11-Feb-09 22:29
Rob Philpott11-Feb-09 22:29 
QuestionHow to make a setup of windows application Pin
Rameez Raja11-Feb-09 20:17
Rameez Raja11-Feb-09 20:17 
AnswerRe: How to make a setup of windows application Pin
Eddy Vluggen11-Feb-09 20:45
professionalEddy Vluggen11-Feb-09 20:45 
AnswerRe: How to make a setup of windows application Pin
Vimalsoft(Pty) Ltd11-Feb-09 22:38
professionalVimalsoft(Pty) Ltd11-Feb-09 22:38 
AnswerRe: How to make a setup of windows application Pin
erfi11-Feb-09 23:19
erfi11-Feb-09 23:19 
AnswerRe: How to make a setup of windows application Pin
DJ-Boris12-Feb-09 0:10
DJ-Boris12-Feb-09 0:10 
QuestionTreeView Pin
Udayaraju11-Feb-09 19:54
Udayaraju11-Feb-09 19:54 
This is My data

CategName subCateName Id Products
NULL NULL 6 Prod3
NULL NULL 9 SalesProd7
Beverages Beers 15 Bell Lager 500 ML
Beverages Beers 16 CLUB PILSENER 500 ML
Beverages Juices 24 Apple Juice
Beverages Juices 25 Chikooo Juice
Beverages SoftDrinks 26 Coke
Beverages SoftDrinks 27 Pepsi
Beverages Wines 28 RED WINE
Beverages Wines 29 White Wine
Food MeatProducts36 GOAT MEAT
Food Fruits 18 APPLE GREEN
Food Fruits 19 LOCAL ORANGES
Others OtherItems 30 BENSON & HEDGES LIGHT
VegeTable NULL 20 BEETROOT
VegeTable NULL 21 TOMATO FRESH

I got the above data into Datatable 'table' and I am trying to insert into tree view
as Categories-subcategories-Products. I have tried the following and my output in such a way i get only
one product for each categorie and sub categorie.

if (table != null)
            {
                foreach (DataRow row in table.Rows)
                {
                    MainNode = new TreeNode(row.ItemArray[0].ToString());
                    MainNode.Name = row.ItemArray[0].ToString();
                    if (MainNode.Text == "")
                    {
                        MainNode = new TreeNode(row.ItemArray[1].ToString());
                        MainNode.Name = row.ItemArray[1].ToString();
                        if (MainNode.Text == "")
                        {
                            MainNode = new TreeNode(row.ItemArray[3].ToString());
                            MainNode.Name = row.ItemArray[3].ToString();
                            MainNode.Tag = row.ItemArray[2].ToString();
                            if (!RootNode.Nodes.ContainsKey(MainNode.Name))
                            {
                                RootNode.Nodes.Add(MainNode);
                            } }
                        else
                        {
                            ChildNode = new TreeNode(row.ItemArray[3].ToString());
                            ChildNode.Name = row.ItemArray[3].ToString();
                            ChildNode.Tag = row.ItemArray[2].ToString();
                            if (!MainNode.Nodes.ContainsKey(ChildNode.Name))
                            {
                                MainNode.Nodes.Add(ChildNode);
                            }
                            if (!RootNode.Nodes.ContainsKey(MainNode.Name))
                            {
                                RootNode.Nodes.Add(MainNode);
                            } } }
                    else
                    {
                        ChildNode = new TreeNode(row.ItemArray[1].ToString());
                        ChildNode.Name = row.ItemArray[1].ToString();
                        if (ChildNode.Text == "")
                        {
                            ChildNode = new TreeNode(row.ItemArray[3].ToString());
                            ChildNode.Name = row.ItemArray[3].ToString();
                            ChildNode.Tag = row.ItemArray[2].ToString();
                            if (!MainNode.Nodes.ContainsKey(ChildNode.Name))
                            {
                                MainNode.Nodes.Add(ChildNode);
                            } }
                        else
                        {
                            SubNode = new TreeNode(row.ItemArray[3].ToString());
                            SubNode.Name = row.ItemArray[3].ToString();
                            SubNode.Tag = row.ItemArray[2].ToString();
                            if (!ChildNode.Nodes.ContainsKey(SubNode.Name))
                            {
                                ChildNode.Nodes.Add(SubNode);
                            } }
                        if (!MainNode.Nodes.ContainsKey(ChildNode.Name))
                        {
                            MainNode.Nodes.Add(ChildNode);
                        }
                        else
                        {
						//Here I am unable to understand how to fill child nodes into mainnode
						//The below code is wrong 
                            for (int i = 0; i <= MainNode.Nodes.Count; i++)
                            {
                                MainNode.Nodes.Add(ChildNode);                                
                            }                   }
                        if (!RootNode.Nodes.ContainsKey(MainNode.Name))
                        {
                            RootNode.Nodes.Add(MainNode);                            
                        }                    }                }            }

Code complexity is more here...(worst) Is there any other way of implementing
like Switch or any other methods.
AnswerRe: TreeView Pin
Udayaraju12-Feb-09 1:15
Udayaraju12-Feb-09 1:15 
AnswerRe: TreeView Pin
Jimmanuel12-Feb-09 3:07
Jimmanuel12-Feb-09 3:07 
GeneralRe: TreeView Pin
Udayaraju15-Feb-09 4:53
Udayaraju15-Feb-09 4:53 
GeneralRe: TreeView Pin
Udayaraju15-Feb-09 5:09
Udayaraju15-Feb-09 5:09 
GeneralRe: TreeView Pin
Udayaraju15-Feb-09 5:20
Udayaraju15-Feb-09 5:20 
QuestionFile Processing Error Pin
MumbleB11-Feb-09 19:53
MumbleB11-Feb-09 19:53 
AnswerRe: File Processing Error Pin
ABitSmart11-Feb-09 21:04
ABitSmart11-Feb-09 21:04 
GeneralRe: File Processing Error Pin
MumbleB11-Feb-09 21:08
MumbleB11-Feb-09 21:08 
AnswerRe: File Processing Error Pin
Eddy Vluggen11-Feb-09 21:25
professionalEddy Vluggen11-Feb-09 21:25 
QuestionOn button click-context menu strip Pin
Udayaraju11-Feb-09 19:47
Udayaraju11-Feb-09 19:47 
AnswerRe: On button click-context menu strip Pin
ABitSmart11-Feb-09 20:08
ABitSmart11-Feb-09 20:08 
AnswerRe: On button click-context menu strip Pin
DaveyM6911-Feb-09 22:56
professionalDaveyM6911-Feb-09 22:56 
GeneralRe: On button click-context menu strip Pin
Udayaraju15-Feb-09 4:54
Udayaraju15-Feb-09 4:54 
GeneralRe: On button click-context menu strip Pin
DaveyM6915-Feb-09 6:33
professionalDaveyM6915-Feb-09 6:33 
Questionc# Pin
aratireddy11-Feb-09 17:14
aratireddy11-Feb-09 17:14 
AnswerRe: c# Pin
ABitSmart11-Feb-09 18:43
ABitSmart11-Feb-09 18:43 
QuestionHow to create and execute of a simple Function with input and output parameters in pl/sql using with c#.net Pin
AnilJayanti11-Feb-09 16:40
AnilJayanti11-Feb-09 16:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.