WPF 中 ListView 如何绑定 SQL 中的数据?
数据库中,有一个表,ID,Name,Price,Num,这几个字段
在WPF 中,我创建了一个ListView,
<ListView HorizontalAlignment="Left"
Name="ListView_De"
Height="176" VerticalAlignment="Top"
Width="472" Margin="7,4,0,0">
<ListView.View>
<GridView>
<GridViewColumn Header="ID" Width="50"/>
<GridViewColumn Header="Name" Width="50"/>
<GridViewColumn Header="Price" Width="50"/>
<GridViewColumn Header="Num" Width="50"/>
</GridView>
</ListView.View>
</ListView>
想对应把数据库中的东西,对应在ListView 中显示。
求对策。。或者,一个类似的Demo
谢谢各位指导了。
------解决方案-------------------- <ListView Name="listView1" MinWidth="280">
<ListView.View>
<GridView x:Name="gridView1">
<GridViewColumn Header="用户名" DisplayMemberBinding="{Binding Path=yhm}"></GridViewColumn>
<GridViewColumn Header="密码" DisplayMemberBinding="{Binding Path=mm}"></GridViewColumn>
<GridViewColumn Header="代码 " DisplayMemberBinding="{Binding Path=bmdm}"></GridViewColumn>
<GridViewColumn Header=" ID" DisplayMemberBinding="{Binding Path=id}"></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
SqlDataAdapter sda;
DataTable dt;
public MainWindow()
{