我是winforms的新手,我正在使用组合框。我喜欢学习如何从数据库加载到控件(组合框)以及如何将值从控件(组合框)保存到数据库字段。
下面我需要一些有关从 Combobox 获取过程并将/选择值放入组合框的帮助...但不知道该怎么做...
下面我获取列表中的所有行并绑定到组合框。这很好用,但喜欢做一些我正在努力的动作。
有人可以建议如何执行这些操作吗?
我想在组合框列表的顶部“添加”一个空值,这样他们也可以在组合框列表中选择一个空值。
从 DB 到 Control 时如何在组合框中选择一个值。我正在这样做,comboboxAccount.SeletedText = _account.Number,但它没有选择。
现在它在组合框中显示“数字”,但我喜欢显示数字+“-”描述。这该怎么做?现在它显示例如 4000 但我喜欢显示“4000 - Description1”
我喜欢将 Account.Id 存储到数据库中而不是 Account.Number 中,但是我该怎么做,因为组合框显示的是数字……所以 SelectedText 不是我想要的。
代码:
public class Account
{
public Int32 Id { get; set; } e.g. 1
public string Number{ get; set; } e.g. 4000 (alpha-numeric)
public string Description1 { get; set; } e.g. Customer
public string Description2 {get; set;} e.g. VAT account
public string Language {get; set;} e.g. EN
}
//returns all rows
IList<Account> _account = new List<Account>(Account_repository.GetAll());
comboboxAccount.DataSource = account;
comboboxAccount.DisplayMember = "Number";
comboboxAccount.Add(??); (see point 1)
//saving to database
Client _client = new Client();
_client.Account = comboboxAccount.??; (see point 4)