开发者

WPF Combo binding to datatable: Strange behaviour

开发者 https://www.devze.com 2023-04-10 04:28 出处:网络
I\'ve a strange problem when trying to bind a WPF combo to a set of column values in a datatable. The binding works fine, but the values in the combo are the individual characters in the first item of

I've a strange problem when trying to bind a WPF combo to a set of column values in a datatable. The binding works fine, but the values in the combo are the individual characters in the first item of the column and not the whole string. (I cannot post image and so uploaded it to the following location)

http://tinypic.com/r/293hx0o/7

My combo is a simple one with no templates and is in a grid with a label in first column and this combo in second column :

 <ComboBox IsTextSearchEnabled="True" IsEditable="True" Name="cbIDef" BorderThickness="1"  Height="28"  Grid.Row="0" Grid.Column="1" BorderBrush="Black" FontSize="15" ItemsSource="{Binding Path=Name}" IsSynchronizedWithCurrentItem="True" SelectedValuePath="Name" />

My code behind:

 Dim lobjDT As New DataTable("TestTable")
 lobjDT.Columns.Add("Poem")
 lobjDT.Columns.Add("Line1")
 lobjDT.Columns.Add("Line2")

 Dim lobjNewRow As DataRow = lobjDT.NewRow

 With lobjNewRow
     .Item(0) = "Baba Black Sheep"
     .Item(1) = "Have you any wool"
     .Item(2) = "Yes sir Yes sir"
 End With

 lobjDT.Rows.Add(lobjNewRow)
 <Some Nested CLR object>.cbIDef.DataContext开发者_如何学运维 = lobjDT

Can someone please enlighten me where I'm going wrong?


Set your binding path as follows

="{DisplayMemberPath =Poem}"

You can see an example at http://www.codeproject.com/KB/WPF/WPFSelectedValue.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号