C# Datagridview 绑定到类不更新
我有一个 datagridview,我将其绑定到一个类。我添加到类中,但 datagridview 没有更新。
我的绑定:
ScannedChecks = new ScannedChecks();
ScannedChecks.AddCheck(DateTime.Now, "22222", "checknumdd", "routingdd", _checkData, 4);
dataGridView1.DataSource = ScannedChecks;
我继续执行 AddCheck 来查看它是否到达了 datagridview,但它没有......不过该类正在更新。
我的班级:
namespace SSS.Ckentry
{
public class ScannedChecks : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public ScannedChecks()
{
ScannedChecksCollection = new ObservableCollection<ScannedCheck>();
}
public void AddCheck(DateTime checkDate, string accountNumber, string checkNumber, string bankRoutingNumber, string bankAccountNumber, decimal checkAmount)
{
var scc = new ScannedCheck
{
CheckDate = checkDate,
AccountNumber = accountNumber,
CheckNumber = checkNumber,
BankRoutingNumber = bankRoutingNumber,
BankAccountNumber = bankAccountNumber,
CheckAmount = checkAmount,
};
ScannedChecksCollection.Add(scc);
}
public ObservableCollection<ScannedCheck> ScannedChecksCollection { get; set; }
public class ScannedCheck
{
public DateTime CheckDate { get; set; }
public string AccountNumber { get; set; }
public string CheckNumber { get; set; }
public string BankRoutingNumber { get; set; }
public string BankAccountNumber { get; set; }
public decimal CheckAmount { get; set; }
}
}
}
谁能告诉我我做错了什么?
非常感谢!
I have a datagridview that I am binding to a class. I add to the class but the datagridview is not updating.
My bind:
ScannedChecks = new ScannedChecks();
ScannedChecks.AddCheck(DateTime.Now, "22222", "checknumdd", "routingdd", _checkData, 4);
dataGridView1.DataSource = ScannedChecks;
I went ahead and did the AddCheck to see if it was reaching the datagridview and it isn't... The class is being updated though.
My class:
namespace SSS.Ckentry
{
public class ScannedChecks : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public ScannedChecks()
{
ScannedChecksCollection = new ObservableCollection<ScannedCheck>();
}
public void AddCheck(DateTime checkDate, string accountNumber, string checkNumber, string bankRoutingNumber, string bankAccountNumber, decimal checkAmount)
{
var scc = new ScannedCheck
{
CheckDate = checkDate,
AccountNumber = accountNumber,
CheckNumber = checkNumber,
BankRoutingNumber = bankRoutingNumber,
BankAccountNumber = bankAccountNumber,
CheckAmount = checkAmount,
};
ScannedChecksCollection.Add(scc);
}
public ObservableCollection<ScannedCheck> ScannedChecksCollection { get; set; }
public class ScannedCheck
{
public DateTime CheckDate { get; set; }
public string AccountNumber { get; set; }
public string CheckNumber { get; set; }
public string BankRoutingNumber { get; set; }
public string BankAccountNumber { get; set; }
public decimal CheckAmount { get; set; }
}
}
}
Can anyone tell me what I am doing wrong?
Thanks much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您用新的 ScannedChecksCollection 替换 ScannedChecksCollection,则属性设置器应触发 PropertyChanged exent。
如果检查是可修改的,ScannedCheck 应该实现 INotifyPropertyChanged
If you ever replace the ScannedChecksCollection with a new ScannedChecksCollection, the property setter should fire the PropertyChanged exent.
If checks are modifiable, ScannedCheck should implement INotifyPropertyChanged
你不应该这样做吗
Shouldn't you be doing