我在组合框中有 valueMember,我需要将此值保存为整数...这是我的代码:
public class Benzinky
{
public int B_cislo { get; set; }
public string Benzinka { get; set; }
}
var lines = File.ReadAllLines(@"C:...\pokus.txt");
var data = lines.Select(l => l.Split());
List<Benzinky> allB = data.Where(arr => arr.Length >= 2
&& arr[1].Trim().All(Char.IsDigit))
.Select(arr =>
new Benzinky
{
Benzinka = arr[0].Trim(),
B_cislo = int.Parse(arr[1].Trim())
})
.ToList();
var bindingSourceB = new BindingSource();
bindingSourceB.DataSource = allB;
comboBox1.DataSource = bindingSourceB;
comboBox1.ValueMember = "B_cislo";
comboBox1.DisplayMember = "Benzinka";
我的文本:
Prague 3106
Berlin 3107
........
你有什么想法吗?