我想用以下内容填充一个组合框:
可见项目/项目值
English / En
Italian / It
Spainish / Sp
etc....
Run Code Online (Sandbox Code Playgroud)
有什么帮助吗?
也可以在填充Combobox后,使其只读?
我有一个带有字符串属性和List属性的简单类,我实现了INofityPropertyChanged事件,但是当我对字符串List执行.Add时,此事件未被命中,因此我的ListView中显示的Converter未被命中.我猜测属性已更改未被添加到列表中....如何实现此方法以获取该属性更改事件命中???
我需要使用其他类型的收藏吗?!
谢谢你的帮助!
namespace SVNQuickOpen.Configuration
{
public class DatabaseRecord : INotifyPropertyChanged
{
public DatabaseRecord()
{
IncludeFolders = new List<string>();
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
protected void Notify(string propName)
{
if (this.PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propName));
}
}
#endregion
private string _name;
public string Name
{
get { return _name; }
set
{
this._name = value;
Notify("Name");
}
}
private List<string> _includeFolders;
public List<string> IncludeFolders
{
get { return _includeFolders; }
set
{
this._includeFolders = value; …Run Code Online (Sandbox Code Playgroud) 如何从sql数据库填充一个组合框(带有id和名称列的学生表),显示文本代表学生的名字,组合框项目的值是该学生的id,当我得到的值时组合框我会得到id值
我需要一些关于WinForms数据绑定的帮助/指导,我似乎无法让Google帮助我解决这个问题.
这是我的情景.考虑以下类似于我需要的类:
public class Car
{
public string Name { get; set; }
public List<Tire> Tires { get; set; }
}
public class Tire
{
public double Pressure { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的实例将是Car类的一个对象,其中包含一个带有四个Tire对象的List.请注意,我将在列表中始终具有已知数量的对象.
现在我想将数据绑定到包含五个文本框的Form.一个带有汽车名称的文本框和一个带有每个轮胎压力的文本框.
有关如何使这项工作的任何想法?VS中的设计者似乎不允许我通过分配像Tires [0] .Pressure这样的列表索引来设置它.
我目前的解决方案是绑定到"BindableCar",就像:
public class BindableCar
{
private Car _car;
public BindableCar(Car car)
{
_car = car;
}
public string Name
{
get { return _car.Name; }
set { _car.Name = value; }
}
public double Tire1Pressure
{
get { return _car.Tires[0].Pressure; }
set …Run Code Online (Sandbox Code Playgroud) 大约3个小时,我正在尝试解决此问题。我的组合框向我显示对象名称而不是一个值,例如:A

这是我的课:
namespace Supermarket
{
public class WhareHouseTable
{
public string name { get; set; }
public double cost { get; set; }
public string offer { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
private void Form1_Load(object sender, EventArgs e)
{
List<WhareHouseTable> product = new List<WhareHouseTable>();
product.Add(new WhareHouseTable { name = "A", cost = 0.63, offer = "Buy 2 for the price of 1" });
product.Add(new WhareHouseTable { name = "B", cost = 0.20 });
product.Add(new WhareHouseTable { name = "C", …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
private void nameTextBox_Leave(object sender, EventArgs e)
{
var names = ConfigurationManager.AppSettings.AllKeys
.Where(k => k.StartsWith("name"))
.ToArray();
// Add names to combobox
comboBox.Items.AddRange(names);
}
Run Code Online (Sandbox Code Playgroud)
问题是每次我Tab从文本框按下,comboBox元素继续加倍.如果有Ken,John,Tim在那里,如果我再次按Tab键,它会显示两次.
我尝试在上面的名称中使用distinct,但是每次创建新的瞬时时都不会执行任何操作,并保存上一个.添加名称后,我无法将comboBox设置为空,因为它在代码中单击后面的按钮时使用.
我认为唯一的替代方法是声明一个全局变量,并确保其值为0,然后只在comboBox中插入值,并在插入值后将其更改为1.但这似乎不是一个好的编码实践.
有没有更好的方法来完成这项工作?
我希望ListBox当我删除或添加一个对象到我用作其的列表时自动显示更改DataSource。
如何将 a 连接List<T>到 aListBox并立即查看底层列表的更改ListBox?