-
January 7th, 2010, 05:57 PM
#1
Simple WPF Treeview binding
Hi,
I am new to WPF and would really appreciate help on an issue Im struggling with. I need to Bind a treeview Item in a WPF treeview in the main app's Menu. All i need is the correct syntax to bind the single datatable to treeview item(XAML and the codebehind) this is what I have so far. Please provide code with your suggestion, your help is appreciated. To make things clear once again I am just trying to Bind the "ItemList" treeview Item's Itemsource. Your helps appreciated
XAML
<Window x:Class="WPFToolkit.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPFToolkit"
Title="Window1" Height="300" Width="300">
<Window.Resources>
</Window.Resources>
<Grid>
<TreeView Name="SampleTree" Margin="-9,0,0,0">
<TreeViewItem Header="Create List"
MouseDoubleClick="CreateCodeset_Click" IsEnabled="True"/>
<TreeViewItem Header="Search List"
MouseDoubleClick="SearchCodeSet_Click" />
<TreeViewItem Header="List Items" Margin="15,0,0,0">
<TreeViewItem Name="ItemList" Header="Codeset 1" Style="{StaticResource listMenuItem}">
</TreeViewItem>
</TreeViewItem>
</TreeView>
</Grid>
</Window>
C#
public void CreateList()
{
DataTable tbl = new DataTable("Items");
tbl.Columns.Add("Name");
DataRow row = tbl.NewRow();
row["Name"] = "Fruits";
tbl.Rows.Add(row);
DataRow row2 = tbl.NewRow();
row["Name"] = "Vegetables";
tbl.Rows.Add(row2);
DataRow row3 = tbl.NewRow();
row["Name"] = "Meats";
tbl.Rows.Add(row3);
DataRow row4 = tbl.NewRow();
row["Name"] = "Drinks";
tbl.Rows.Add(row4);
DataRow row5 = tbl.NewRow();
row["Name"] = "Bread";
tbl.Rows.Add(row5);
//This is not working
ItemList.IItemsSource = tbl.Select();
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|