C# WPF ListView 数据库

来源:互联网 发布:淘宝如何优化宝贝标题 编辑:程序博客网 时间:2024/05/16 01:18
~~~xmal中的代码~~~只贴ListView控件代码~~~
<ListView Name="listView" Grid.Row="1" Grid.ColumnSpan="2" Margin="20,50" SelectionChanged="listView_SelectionChanged" >                <ListView.View>                    <GridView>                        <GridViewColumn Header="姓名" DisplayMemberBinding="{Binding Path=CusName}" Width="40"/>                        <GridViewColumn Header="地址" DisplayMemberBinding="{Binding Path=CusArea}" Width="130"/>                        <GridViewColumn Header="电话" DisplayMemberBinding="{Binding Path=CusTel}" Width="118"/>                    </GridView>                </ListView.View>            </ListView>
~~~新建类Customer.cs代码~~~
class Customer    {        public string CusName { get; set; }        public string CusArea { get; set; }        public string CusTel { get; set; }    }
~~~.xmal.cs代码~~~
        private void btnOk_Click(object sender, RoutedEventArgs e)        {            DataTable table = SqlHelper.ExecuteDataTable("select * from T_Test where CusName=@CustName",new SqlParameter("@CustName",txtName.Text));            List<Customer> ltCus=new List<Customer> ();            foreach (DataRow dataRow in table.Rows)            {                Customer cus = new Customer();                cus.CusName=(string)dataRow["CusName"];                cus.CusArea=(string)dataRow["CusArea"];                cus.CusTel=(string)dataRow["CusTel"];                ltCus.Add(cus);            }            listView.ItemsSource = ltCus;        }

数据库的一些~~~引用啊~~~SqlHelper.cs啊~~~App.config配置啊~~~神马的就不出来浪费大家时间了吐舌头

来张效果图...