首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件开发 >

深入显出WPF 第二部分(4)

2012-12-18 
深入浅出WPF 第二部分(4)6.3.7 使用集合对象作为列表控件的ItemsSourcepublic MainWindow(){InitializeCom

深入浅出WPF 第二部分(4)

6.3.7 使用集合对象作为列表控件的ItemsSource

        public MainWindow()        {            InitializeComponent();            //Another bind source method            //this.listViewStudents.ItemsSource=Load().DefaultView;                        this.listViewStudents.DataContext = Load();            this.listViewStudents.SetBinding(ListView.ItemsSourceProperty, new Binding());            this.textBoxId.SetBinding(TextBox.TextProperty, new Binding("SelectedItem.Id") { Source = listViewStudents, Mode = BindingMode.OneWay });        }        private DataTable Load()        {            var connStr = "Data Source=(local);Initial Catalog=AndersDB;Integrated Security=True";            SqlCommand sqlComm = new SqlCommand("select * from Student", new SqlConnection(connStr));            SqlDataAdapter sqlDA = new SqlDataAdapter(sqlComm);            DataSet ds = new DataSet();            sqlDA.Fill(ds);            return ds.Tables[0];        }


热点排行