WPF Combo 绑定到数据表:奇怪的行为
当尝试将 WPF 组合绑定到数据表中的一组列值时,我遇到了一个奇怪的问题。绑定工作正常,但组合中的值是列第一项中的单个字符,而不是整个字符串。 (我无法发布图片,因此将其上传到以下位置)
http://tinypic.com/r/293hx0o /7
我的组合是一个简单的组合,没有模板,位于网格中,第一列中有一个标签,第二列中有这个组合:
<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" />
我的代码背后:
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
有人可以告诉我哪里出错了吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
设置绑定路径如下
="{DisplayMemberPath =Poem}"
您可以在 http 中查看示例://www.codeproject.com/KB/WPF/WPFSelectedValue.aspx
Set your binding path as follows
="{DisplayMemberPath =Poem}"
You can see an example at http://www.codeproject.com/KB/WPF/WPFSelectedValue.aspx