WinformsとWPFのComboBox+DataTableのコードの違い
DataTableを使ってComboBoxのリストをバインドする方法についてWinformsとWPFの違いです。DataTableはSQLiteから作成していますが、その部分は共通です。
Winforms
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | private void Main() { cboCvo.DataSource = cvo(); } private DataTable cvo() { DataTable dt = new DataTable(); using (SQLiteConnection con = new SQLiteConnection( "Data Source=" + DatabasePath)) { SQLiteDataAdapter adp = new SQLiteDataAdapter( "SELECT * from cvo order by no;" , con); adp.Fill(dt); } return dt; } |
WPF
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | private void Main() { cboCvo.ItemsSource = ((IListSource)cvo()).GetList(); } private DataTable cvo() { DataTable dt = new DataTable(); using (SQLiteConnection con = new SQLiteConnection( "Data Source=" + DatabasePath)) { SQLiteDataAdapter adp = new SQLiteDataAdapter( "SELECT * from cvo order by no;" , con); adp.Fill(dt); } return dt; } |