Datagridview实时计算 [英] Datagridview Real-Time Calculation
本文介绍了Datagridview实时计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨大家好!
需要帮助:
名称------单位-------价值
Kappa ------ kg ---------- 1
Delta ------- m ----- ------ 2
Alpha ------- mm -------- 3
现在,我想在datagridview上编辑Value,每当我输入一个数字时,我想自动计算其他值。我怎样才能做到这一点?需要帮助!
Hi Guys!
Need help with this:
Name------Unit-------Value
Kappa------kg----------1
Delta-------m-----------2
Alpha-------mm--------3
Now, I want to edit the Value on the datagridview, and everytime I enter a number I want to automatically calculated the other values. How can I do this? Need HELP!
推荐答案
您需要在绑定到此网格的集合中处理此问题,遵循以下准则:
- 创建一个A类来保存一行的数据,并在其上实现INotifyPropertyChanged
- 创建另一个具有A对象集合作为属性的类
- 创建A类的每个实例,订阅它的PropertyChanged事件,并添加到集合中
- 重新计算值并更新PropertyChanged事件处理程序中集合中的项目
- 实现INotifyPropertyChanged时应确保在将集合绑定到网格时自动刷新网格。
You need to take care of this in the collection that is bound to this grid, following these guidelines:
- Create a class A to hold the data for one row, and implement INotifyPropertyChanged on it
- Create another class that has the collection of A objects as a property
- Create each instance of class A, subscribe to the PropertyChanged event of it, and add to the collection
- Recalculate the values and update the items in the collection in your PropertyChanged event handler
- Implementing INotifyPropertyChanged should make sure that your grid is refreshed automatically when you bind the collection to it.
这篇关于Datagridview实时计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文