I am developing a c# wpf application.It needs a treeview to display the names of students according to their courses.
For Example i have 10 courses(1-10 courses) and i have database with the student name and their course name.
anyone give me example to display the student name under course name. and if we select the student name then regarding action should be applied.
Actually i developed the code for this and the student name is no selecting(not highlighted) when i click on student name.
Here is my code
tree1.Items.Clear();
TreeViewItem item1, item2, item3, item4, item5, item6, item7, item8, item9, item10;
String[] cl1,cl2,cl3,cl4,cl5,cl6,cl7,cl8,cl9,cl10;
item1 = new TreeViewItem();
item1.Header = "1st Class";
item2 = new TreeViewItem();
item2.Header = "2nd Class";
item3 = new TreeViewItem();
item3.Header = "3rd Class";
item4 = new TreeViewItem();
item4.Header = "4th Class";
item5 = new TreeViewItem();
item5.Header = "5h Class";
item6 = new TreeViewItem();
item6.Header = "6th Class";
item7 = new TreeViewItem();
item7.Header = "7th Class";
item8 = new TreeViewItem();
item8.Header = "8th Class";
item9 = new TreeViewItem();
item9.Header = "9th Class";
item10 = new TreeViewItem();
item10.Header = "10th Class";
tree1.Items.Add(item1);
tree1.Items.Add(item2);
tree1.Items.Add(item3);
tree1.Items.Add(item4);
tree1.Items.Add(item5);
tree1.Items.Add(item6);
tree1.Items.Add(item7);
tree1.Items.Add(item8);
tree1.Items.Add(item9);
tree1.Items.Add(item10);
SqlCeConnection connection = new SqlCeConnection(@"Data Source=|DataDirectory|\Database1.sdf");
connection.Open();
SqlCeCommand cmd1 = new SqlCeCommand("SELECT * FROM StData ORDER BY Class ASC", connection);
SqlCeDataReader reader = cmd1.ExecuteReader();
while (reader.Read())
{
if (reader.GetString(3) == "1st Class")
{
item1.Items.Add(reader.GetString(0).ToString());
}
else if (reader.GetString(3) == "2nd Class")
{
item2.Items.Add(reader.GetString(0).ToString());
}
else if (reader.GetString(3) == "3rd Class")
{
item3.Items.Add(reader.GetString(0).ToString());
}
else if (reader.GetString(3) == "4th Class")
{
item4.Items.Add(reader.GetString(0).ToString());
}
else if (reader.GetString(3) == "5th Class")
{
item5.Items.Add(reader.GetString(0).ToString());
}
else if (reader.GetString(3) == "6th Class")
{
item6.Items.Add(reader.GetString(0).ToString());
}
else if (reader.GetString(3) == "7th Class")
{
item7.Items.Add(reader.GetString(0).ToString());
}
else if (reader.GetString(3) == "8th Class")
{
item8.Items.Add(reader.GetString(0).ToString());
}
else if (reader.GetString(3) == "9th Class")
{
item9.Items.Add(reader.GetString(0).ToString());
}
else if (reader.GetString(3) == "10th Class")
{
item10.Items.Add(reader.GetString(0).ToString());
}
}
Anyone correct my code and tell me how to make student name get select and take corresponding action.