In order to display a data table in a ListView I have
<ListView ItemsSource="{Binding Source={StaticResource AdministrationView}}" IsSynchronizedWithCurrentItem="True" Name="lvTable">
<ListView.ItemContainerStyle> ... stuff ... </ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn Header="Pattern">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding Path=Pattern}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Account">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding Path=AccountName}" />
.... closing tags .......
with resource
<Window.Resources>
<CollectionViewSource x:Key="AdministrationView"/>
</Window.Resources>
and code behind
var db = new XDataContext();
var data = db.Translations;
var viewSource = (CollectionViewSource)FindResource("AdministrationView");
viewSource.Source = data;
=====
Now, if I want to display one of several possible tables, I'd like to bind in code, so I have
data = ....
var tb = new TextBox();
var binding = new Binding("Pattern");
binding.Source = db.Accounts;
tb.SetBinding(TextBlock.TextProperty, binding);
but I can't figure out how to attach the TextBox to one of the GridViewColumn(s).
Any thoughts?
Thanks