473,395 Members | 1,462 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Q: Logic for TreeView

Hi,

I am learning C# at the moment. I am trying to develop a simple program that
will get data from a MS Access database into a dataSet. The result of
dataSet should be something like:

Year Semester Code Task
---------------------------------------------------
"2003" "One" "CSE9020" "Deliverable Item 1"
"2003" "One" "CSE9020" "Deliverable Item 2"
"2003" "One" "CSE9020" "Deliverable Item 3"
"2003" "One" "CSE9020" "Deliverable Item 4"
"2003" "One" "CSE9020" "Deliverable Item 5"
"2003" "Two" "CSE9020" "Deliverable Item 1"
"2003" "Two" "CSE9020" "Deliverable Item 2"
"2003" "Two" "CSE9020" "Deliverable Item 3"
Now I have to populate a TreeView from the dataSet. I have learnt how to
populate TreeView Nodes from
http://www.codeproject.com/cs/database/2dtreeview.asp and some other online
examples. But I am struggling to come out with the programming logic so that
I may populate a TreeView Nodes like:

-Year
- Semester
- Code
- Task
- Semester
- Code
- Task
- Code
- Task
- Task
- Year

Can someone give me some hint?

Thank you.

--
Soul

Nov 15 '05 #1
3 3218
My test codes are as follow, but obviously I am wrong as it come out with 8
times of 2003 and in each 2003, it will contain 5 times of semester one, 3
times of semester two.

for (int i = 0; i < this.dataSet.Tables[0].Rows.Count; i++)
{
TreeNode yearNode = this.treeView.Nodes.Add("Year: " +
this.dataSet.Tables[0].Rows[i]["subjectYear"].ToString());
dataView.RowFilter = "subjectYear = " +
this.dataSet.Tables[0].Rows[i]["subjectYear"].ToString();

foreach (DataRowView row1 in dataView)
{
TreeNode semesterNode = yearNode.Nodes.Add("Sem: " +
row1["subjectSemester"].ToString());
dataView.RowFilter = "subjectSemester = " +
row1["subjectSemester"].ToString();

foreach (DataRowView row2 in dataView)
{
TreeNode codeNode =
semesterNode.Nodes.Add(row2["subjectCode"].ToString());
}
}
}

--
Soul
"Soul" <no@spam.com> wrote in message
news:us**************@TK2MSFTNGP12.phx.gbl...
| Hi,
|
| I am learning C# at the moment. I am trying to develop a simple program
that
| will get data from a MS Access database into a dataSet. The result of
| dataSet should be something like:
|
| Year Semester Code Task
| ---------------------------------------------------
| "2003" "One" "CSE9020" "Deliverable Item 1"
| "2003" "One" "CSE9020" "Deliverable Item 2"
| "2003" "One" "CSE9020" "Deliverable Item 3"
| "2003" "One" "CSE9020" "Deliverable Item 4"
| "2003" "One" "CSE9020" "Deliverable Item 5"
| "2003" "Two" "CSE9020" "Deliverable Item 1"
| "2003" "Two" "CSE9020" "Deliverable Item 2"
| "2003" "Two" "CSE9020" "Deliverable Item 3"
|
|
| Now I have to populate a TreeView from the dataSet. I have learnt how to
| populate TreeView Nodes from
| http://www.codeproject.com/cs/database/2dtreeview.asp and some other
online
| examples. But I am struggling to come out with the programming logic so
that
| I may populate a TreeView Nodes like:
|
| -Year
| - Semester
| - Code
| - Task
| - Semester
| - Code
| - Task
| - Code
| - Task
| - Task
| - Year
|
| Can someone give me some hint?
|
| Thank you.
|
| --
| Soul
|
|
|

Nov 15 '05 #2

Hi Soul,

I think there are some problem in your program logic of manipulating the
dataset to display in the TreeView.
I think you can just use "for" statement to loop through the dataset rows
and add the different cells into the TreeView.

Hope this helps,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Reply-To: "Soul" <so********@antisocial.com>
| From: "Soul" <no@spam.com>
| References: <us**************@TK2MSFTNGP12.phx.gbl>
| Subject: Re: Logic for TreeView
| Date: Wed, 8 Oct 2003 01:41:07 +1000
| Lines: 81
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="utf-8"
| Content-Transfer-Encoding: 7bit
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <uF**************@TK2MSFTNGP09.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: dsl-203-113-207-187.vic.netspace.net.au 203.113.207.187
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP09.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:189585
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| My test codes are as follow, but obviously I am wrong as it come out with
8
| times of 2003 and in each 2003, it will contain 5 times of semester one, 3
| times of semester two.
|
| for (int i = 0; i < this.dataSet.Tables[0].Rows.Count; i++)
| {
| TreeNode yearNode = this.treeView.Nodes.Add("Year: " +
| this.dataSet.Tables[0].Rows[i]["subjectYear"].ToString());
| dataView.RowFilter = "subjectYear = " +
| this.dataSet.Tables[0].Rows[i]["subjectYear"].ToString();
|
| foreach (DataRowView row1 in dataView)
| {
| TreeNode semesterNode = yearNode.Nodes.Add("Sem: " +
| row1["subjectSemester"].ToString());
| dataView.RowFilter = "subjectSemester = " +
| row1["subjectSemester"].ToString();
|
| foreach (DataRowView row2 in dataView)
| {
| TreeNode codeNode =
| semesterNode.Nodes.Add(row2["subjectCode"].ToString());
| }
| }
| }
|
| --
| Soul
|
|
| "Soul" <no@spam.com> wrote in message
| news:us**************@TK2MSFTNGP12.phx.gbl...
| | Hi,
| |
| | I am learning C# at the moment. I am trying to develop a simple program
| that
| | will get data from a MS Access database into a dataSet. The result of
| | dataSet should be something like:
| |
| | Year Semester Code Task
| | ---------------------------------------------------
| | "2003" "One" "CSE9020" "Deliverable Item 1"
| | "2003" "One" "CSE9020" "Deliverable Item 2"
| | "2003" "One" "CSE9020" "Deliverable Item 3"
| | "2003" "One" "CSE9020" "Deliverable Item 4"
| | "2003" "One" "CSE9020" "Deliverable Item 5"
| | "2003" "Two" "CSE9020" "Deliverable Item 1"
| | "2003" "Two" "CSE9020" "Deliverable Item 2"
| | "2003" "Two" "CSE9020" "Deliverable Item 3"
| |
| |
| | Now I have to populate a TreeView from the dataSet. I have learnt how to
| | populate TreeView Nodes from
| | http://www.codeproject.com/cs/database/2dtreeview.asp and some other
| online
| | examples. But I am struggling to come out with the programming logic so
| that
| | I may populate a TreeView Nodes like:
| |
| | -Year
| | - Semester
| | - Code
| | - Task
| | - Semester
| | - Code
| | - Task
| | - Code
| | - Task
| | - Task
| | - Year
| |
| | Can someone give me some hint?
| |
| | Thank you.
| |
| | --
| | Soul
| |
| |
| |
|
|

Nov 15 '05 #3

Hi Soul,

Do you understand my meanning?
You should use the simplest program logic to add your treenode through
"for" statement.
You should add the root nodes first(loop through Year column), then add the
second level nodes(loop through the Semester column)....

If you still feel anything unclear, please feel free to let me know.

Hope this helps,
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Reply-To: "Soul" <so********@antisocial.com>
| From: "Soul" <no@spam.com>
| References: <us**************@TK2MSFTNGP12.phx.gbl>
| Subject: Re: Logic for TreeView
| Date: Wed, 8 Oct 2003 01:41:07 +1000
| Lines: 81
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="utf-8"
| Content-Transfer-Encoding: 7bit
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <uF**************@TK2MSFTNGP09.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: dsl-203-113-207-187.vic.netspace.net.au 203.113.207.187
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP09.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:189585
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| My test codes are as follow, but obviously I am wrong as it come out with
8
| times of 2003 and in each 2003, it will contain 5 times of semester one, 3
| times of semester two.
|
| for (int i = 0; i < this.dataSet.Tables[0].Rows.Count; i++)
| {
| TreeNode yearNode = this.treeView.Nodes.Add("Year: " +
| this.dataSet.Tables[0].Rows[i]["subjectYear"].ToString());
| dataView.RowFilter = "subjectYear = " +
| this.dataSet.Tables[0].Rows[i]["subjectYear"].ToString();
|
| foreach (DataRowView row1 in dataView)
| {
| TreeNode semesterNode = yearNode.Nodes.Add("Sem: " +
| row1["subjectSemester"].ToString());
| dataView.RowFilter = "subjectSemester = " +
| row1["subjectSemester"].ToString();
|
| foreach (DataRowView row2 in dataView)
| {
| TreeNode codeNode =
| semesterNode.Nodes.Add(row2["subjectCode"].ToString());
| }
| }
| }
|
| --
| Soul
|
|
| "Soul" <no@spam.com> wrote in message
| news:us**************@TK2MSFTNGP12.phx.gbl...
| | Hi,
| |
| | I am learning C# at the moment. I am trying to develop a simple program
| that
| | will get data from a MS Access database into a dataSet. The result of
| | dataSet should be something like:
| |
| | Year Semester Code Task
| | ---------------------------------------------------
| | "2003" "One" "CSE9020" "Deliverable Item 1"
| | "2003" "One" "CSE9020" "Deliverable Item 2"
| | "2003" "One" "CSE9020" "Deliverable Item 3"
| | "2003" "One" "CSE9020" "Deliverable Item 4"
| | "2003" "One" "CSE9020" "Deliverable Item 5"
| | "2003" "Two" "CSE9020" "Deliverable Item 1"
| | "2003" "Two" "CSE9020" "Deliverable Item 2"
| | "2003" "Two" "CSE9020" "Deliverable Item 3"
| |
| |
| | Now I have to populate a TreeView from the dataSet. I have learnt how to
| | populate TreeView Nodes from
| | http://www.codeproject.com/cs/database/2dtreeview.asp and some other
| online
| | examples. But I am struggling to come out with the programming logic so
| that
| | I may populate a TreeView Nodes like:
| |
| | -Year
| | - Semester
| | - Code
| | - Task
| | - Semester
| | - Code
| | - Task
| | - Code
| | - Task
| | - Task
| | - Year
| |
| | Can someone give me some hint?
| |
| | Thank you.
| |
| | --
| | Soul
| |
| |
| |
|
|

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

42
by: lauren quantrell | last post by:
So many postings on not to use the treeview control, but nothing recently. Is it safe to swim there yet with Access 2000-Access 2003?
1
by: Ty Moffett | last post by:
I am new to C# and developing in general. During my studies I got an idea for a program that would basically be Windows Explorer with the added ability to show the size of each and every folder...
5
by: SoKool | last post by:
Can anyone point me to a site where I can get a free treeview control to use in ASP .NET or any tutorial that can help me build my own treeview control. I intend to use a treeview to generate a...
3
by: Peter | last post by:
Hello, We are inserting a side menu to our application using a class that is writing HTML on all our pages. This is a part of the code as an example: writer.Write(" <table WIDTH=""100%""...
6
by: L.M | last post by:
Hello, I knew how to use the treeview under VB6. After migrating to .NET, well, I'm lost. I try to add a new node, either to the same level or as a child to a selected node in the treeview....
14
by: Mr.D | last post by:
How do I save/load the contents of a Treeview to a file? I have found several good examples written i VB6, but not a single one for VB.NET. Please help. ---- Tim
8
by: Matt MacDonald | last post by:
Hi All, I have a form that displays hierarchical categories in a treeview. Ok so far so good. What I was to do is have users be able to select a node in the treeview as part of filling out the...
0
by: Unter | last post by:
Hi all My Treeview is working fine with the following layout 1 Parent 2 Parent 1 Child 2 Child 3 Parent
3
by: Unter | last post by:
Hi all My Treeview is working fine with the following layout 1 Parent 2 Parent 1 Child 2 Child 3 Parent
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.