So In the end I am looking for something like:
2005
--August
----My birthday
2010
--January
----New years eve
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Finisar.SQLite;
using System.Collections;
namespace myNameSpace
{
class classTreeListFromSqlite
{
public static TreeView fillTree(TreeView foo)
{
#region dbConnectAndFill
//SQLite Connection Info
SQLiteConnection sql_con;
SQLiteCommand sql_cmd;
SQLiteDataAdapter DB;
DataSet DS = new DataSet();
sql_con = new SQLiteConnection
("Data Source=test.db;Version=3;New=False;Compress=True;");
sql_con.Open();
sql_cmd = sql_con.CreateCommand();
string CommandText = "select * From User_Journals Order By ID desc";
DB = new SQLiteDataAdapter(CommandText, sql_con);
DS.Reset();
DB.Fill(DS);
sql_con.Close();
#endregion
#region sortYearNodes
//Start Sorting the years and placing
//them into the TreeView as Nodes
ArrayList tempYearList = new ArrayList();
ArrayList yearList = new ArrayList();
List<DataRow> dataList = new List<DataRow>();
foreach (DataRow theRow in DS.Tables[0].Rows)
{
tempYearList.Add(theRow["year"].ToString());
}
tempYearList.Sort();
for (int i = 1; i <= tempYearList.Count - 1; i++)
{
object o = tempYearList[i];
if (yearList.Contains(o))
{
}
else
{
yearList.Add(o);
}
}
int x = 0;
foreach (string yearString in yearList)
{
TreeNode yearNod = new TreeNode();
yearNod.Text = yearList[x].ToString();
foo.Nodes.Add(yearNod);
x++;
}
#endregion
#region sortMonthNodes
//Start sorting the months
ArrayList tempMonthList = new ArrayList();
ArrayList monthList = new ArrayList();
foreach (DataRow theRow in DS.Tables[0].Rows)
{
tempMonthList.Add(theRow["month"].ToString());
}
tempMonthList.Sort();
for (int i = 0; i <= tempMonthList.Count - 1; i++)
{
object o = tempMonthList[i];
if (monthList.Contains(o))
{
}
else
{
monthList.Add(o);
}
}
for (int i = 0; i < monthList.Count; i++)
{
//Start Connect to DB
SQLiteCommand sql_month_cmd;
SQLiteDataAdapter month_DB;
DataSet month_DS = new DataSet();
sql_con.Open();
sql_month_cmd = sql_con.CreateCommand();
string month_CommandText = "SELECT year FROM User_Journals WHERE month = " + monthList[i] + "";
month_DB = new SQLiteDataAdapter(month_CommandText, sql_con);
month_DS.Reset();
month_DB.Fill(month_DS);
sql_con.Close();
//End Connect to DB
foreach (DataRow theRow in month_DS.Tables[0].Rows)
{
object o = theRow["year"].ToString();
#region monthNumericToEnglish
switch (monthList[i].ToString())
{
case "1":
monthList[i] = "January";
break;
case "2":
monthList[i] = "February";
break;
case "3":
monthList[i] = "March";
break;
case "4":
monthList[i] = "April";
break;
case "5":
monthList[i] = "May";
break;
case "6":
monthList[i] = "June";
break;
case "7":
monthList[i] = "July";
break;
case "8":
monthList[i] = "August";
break;
case "9":
monthList[i] = "September";
break;
case "10":
monthList[i] = "October";
break;
case "11":
monthList[i] = "November";
break;
case "12":
monthList[i] = "December";
break;
}
#endregion
int yearListIndex = yearList.IndexOf(o);
TreeNode monthNod = new TreeNode();
monthNod.Text = monthList[i].ToString();
//MessageBox.Show("Contains: " + foo.Nodes[yearListIndex].Nodes.Contains(monthNod));
if(foo.Nodes[yearListIndex].Nodes.Contains(monthNod).ToString() == "False")
{
}
else
{
}
foo.Nodes[yearListIndex].Nodes.Add(monthNod);
MessageBox.Show("Contains: " + foo.Nodes[yearListIndex].Nodes.Contains(monthNod));
}
}
#endregion
foo.ExpandAll();
return foo;
}
}
}


Sign In
Create Account


Back to top










