XAML:綁定組合框在數據網格
<ComboBox SelectionChanged="status_SelectionChanged" Height="23" Name="status" ItemsSource="{Binding}" Width="120">
</ComboBox>
如何從數據庫中作爲我的組合框的ItemsSource時添加的項目?
MySqlCommand status_db = new MySqlCommand("select name from request_status", conn);
這樣:
List<string> combolist = new List<string>();
MySqlDataReader reader = status_db.ExecuteReader();
while (reader.Read())
{
combolist.Add((string)reader);
}
而且是錯誤的...
'從查詢中建立一個列表'怎麼樣? – MexVl 2012-07-10 08:12:02
那麼這是一個SQL問題,而不是一個WPF一個:) http://stackoverflow.com/questions/7061329/mysqlcommand-executereader-getstring-does-not-work。檢查更多關於如何使用MySqlCommand的內容 – MBen 2012-07-10 08:19:19
combolist是否爲空?正如我所描述的那樣,您是否將其設置爲dataContext? – MBen 2012-07-10 08:21:04