开发者

WPF DataGrid Databindung to MySql

开发者 https://www.devze.com 2023-03-04 17:45 出处:网络
I want to bind a MySQL database to my WPF GridView. B开发者_运维技巧ut this doesn\'t work. I would like to do this:

I want to bind a MySQL database to my WPF GridView. B开发者_运维技巧ut this doesn't work. I would like to do this:

MySqlDataAdapter adapter = new MySqlDataAdapter(query, connection);
MySqlCommandBuilder builder = new MySqlCommandBuilder(adapter);
DataTable table = new DataTable();
adapter.Fill(table);
BindingSource source = new BindingSource();
source.DataSource = table;
areaDataGrid.DataContext = table;

But the gid is empty. Why?


You need to set the ItemsSource property


Here is a great article that walks you through exactly how to DataBind with the WPF DataGrid: http://www.codeproject.com/KB/WPF/WPFDataGridExamples.aspx

0

精彩评论

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