hi everyone! i am new in wpf so forgive me i want more!!! i am trying to build an application. i have a treeview that bounded a datasource. it is okay. i have two problems. First; how can i select an item from treeview? i wanna a new window popsup when i select an item; when i click another item; another window popsup. Second problem is that i can not change foreground and font.Thanks everyone in advance
namespace CellBiology { public partial class TreeView { public TreeView() { this.InitializeComponent(); BindTreeView();
}
public void BindTreeView()
{
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\CellBiology.mdb;Persist Security Info=True");
try
{
con.Open();
OleDbCommand cmd = new OleDbCommand("Select * from Topics", con);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "Topics");
int row = ds.Tables["Topics"].Rows.Count;
List<MyMenuItem> myList = new List<MyMenuItem>();
if (row > 0)
{
for (int i = 0; i <= row - 1; i++)
{
myList.Add(new MyMenuItem(Convert.ToInt32(ds.Tables["Topics"].Rows[i][0].ToString()), ds.Tables["Topics"].Rows[i][1].ToString(), 0));
for (int j = 0; j <= row - 1; j++)
{
if (ds.Tables["Topics"].Rows[i][0].ToString() == ds.Tables["Topics"].Rows[j][2].ToString())
{
myList.Add(new MyMenuItem(Convert.ToInt32(ds.Tables["Topics"].Rows[j][0].ToString()), ds.Tables["Topics"].Rows[j][1].ToString(), Convert.ToInt32(ds.Tables["Topics"].Rows[i][0].ToString())));
for (int k = 0; k <= row - 1; k++)
{
if (ds.Tables["Topics"].Rows[j][0].ToString() == ds.Tables["Topics"].Rows[k][2].ToString())
{
myList.Add(new MyMenuItem(Convert.ToInt32(ds.Tables["Topics"].Rows[k][0].ToString()),
ds.Tables["Topics"].Rows[k][1].ToString(),
Convert.ToInt32(ds.Tables["Topics"].Rows[j][0].ToString())));
for (int l = 0; l <= row - 1; l++)
if (ds.Tables["Topics"].Rows[k][0].ToString() == ds.Tables["Topics"].Rows[l][2].ToString())
{
myList.Add(new MyMenuItem(Convert.ToInt32(ds.Tables["Topics"].Rows[l][0].ToString()),
ds.Tables["Topics"].Rows[l][1].ToString(), Convert.ToInt32(ds.Tables["Topics"].Rows[k][0].ToString())));
Dictionary<int, TreeViewItem> flattenedTree = new Dictionary<int, TreeViewItem>();
foreach (MyMenuItem item in myList)
{
TreeViewItem treenode = new TreeViewItem();
treenode.Header = item.TopicName;
treenode.Tag = item;
flattenedTree.Add(item.TopicID, treenode);
if (flattenedTree.ContainsKey(item.TopLevelID))
{
flattenedTree[item.TopLevelID].Items.Add(treenode);
}
else
{
myTreeView.Items.Add(treenode);
}
public class MyMenuItem
{
internal int TopicID { get; set; }
internal string TopicName { get; set; }
internal int TopLevelID { get; set; }
internal MyMenuItem(int topicid, string topicname, int toplevelid)
{
TopicID = topicid;
TopicName = topicname;
TopLevelID = toplevelid;
private void myTreeView_SelectedItemChanged(object sender, RoutedEventArgs e)
{
**how can i code here?**
}
}
}