BindingSource 和 DataGridView 默认当前位置
BindingSource 是否有自动默认当前位置?我在 CurrentCellChanged 事件上有一个事件处理程序,它似乎触发了两次。我正在使用 BindingSource Find 方法以编程方式设置起始位置,但在设置该起始位置之前,CurrentCellChanged 已经触发,并且初始选定的单元格是第 0 列第 0 行。当您创建 BindingSource 时,它是否已经设置了 Current财产?
Does the BindingSource have an automatic default current position? I have an event handler on CurrentCellChanged event and it seems to be firing twice. I am programatically setting the starting position using the BindingSource Find method at that works but before im setting that starting position, the CurrentCellChanged is already firing and the initial selected cell is column 0 row 0. When you create a BindingSource is it already setting the Current property?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
MSDN 中提到 DataGridView.CurrentCell 属性默认的 CurrentCell 属性值为第一行中的第一个单元格(如果 DGV 中没有单元格则为 null)。
设置此默认值将触发 CurrentCellChanged 事件,解释为什么您会看到单元格 0、0 的事件。
MSDN for DataGridView.CurrentCell Property mentions the default CurrentCell property value is the first cell in the first row (or null if there are no cells in the DGV).
Setting this default would fire your CurrentCellChanged event, explaining why you're seeing the event for cell 0, 0.
我很确定您所看到的是 DataGridView 在数据绑定过程中触发其各种选择事件(CurrentCellChanged、SelectionChanged 等...)。因为您已将事件处理程序附加到它触发的这些事件之一。
解决此问题的方法是将事件处理程序附加到 DataGridView 的 DataBindingComplete 并在那里附加您的 CurrentCellChanged 处理程序。
I'm pretty sure what you are seeing is the DataGridView firing its various selection events (CurrentCellChanged, SelectionChanged etc...) during the databinding process. Because you have attached an eventhandler to one of these events it fires.
The way around this is to attach an eventhandler to the DataGridView's DataBindingComplete and attach your CurrentCellChanged handler there.