【发布时间】:2015-05-16 16:36:37
【问题描述】:
我有一个绑定到我的 dataGridView 的 BindingList。 Item 类是这样的;
public class Item : INotifyPropertyChanged
{
private string _Name;
private bool _Active;
public event PropertyChangedEventHandler PropertyChanged;
public string Name
{
get { return _Name; }
set {
_Name = value;
this.NotifyPropertyChanged("Name");
}
}
public bool Active
{
get { return _Active; }
set {
_Active = value;
this.NotifyPropertyChanged("Active");
}
}
private void NotifyPropertyChanged(string name)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
然后我有 Bindinglist 和 dataGridView;
BindingList<Item> ItemList = new BindingList<Item>();
dataGridView1.DataSource = ItemList;
当它为真时,我希望 bool Active 在 dataGridView 上显示为 Checked 图像,否则不显示任何内容。 dataGridView 顶部的按钮允许用户将行标记为活动。
目前 dataGridView 显示一个复选框。如何将项目对象中的布尔值正确绑定到 dataGridView 中的图像?
【问题讨论】:
标签: c# winforms data-binding datagridview