单元格/行计数
我有一个包含 13 列的 DataGridView。大多数行都已满,但有些行有空列。对于每个空列,都有一个 emptyCellCounter
来跟踪有多少个空单元格......并且对于具有空单元格的每一行,都有一个 emptyRowCounter
。
因此可能有 15 个空行和 89 个空单元格。当用户编辑单元格时,我想使用“lineCounter”函数重新计算 emptyCellCounter
以及 emptyRowCounter
。
问题
- 编辑单元格时如何更改此计数器?
I have a DataGridView that contains 13 columns. Most of the rows are completely full but some rows have empty columns. For each empty column there is an emptyCellCounter
that keeps track of how many empty cells there are.. and for each row that has an empty cell there is an emptyRowCounter
.
So there could be 15 empty rows and 89 empty cells. When a user edits a cell I want to recalculate the emptyCellCounter
as well as the emptyRowCounter
using my "lineCounter" function.
QUESTION
- How do I change this counter when a cell is edited?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用事件来了解单元格的值何时发生更改。选择数据网格后,查看属性窗口上的事件。然后双击单元格,VS 会在代码中为您添加一个默认事件。
编辑:
请注意,Davide Piras 使用 CellValidated 事件的方式可能更适合您。如果单元格无效,您可能不想调用 lineCounter 方法。
You can use events to know when the values of the cells have changed. Look at the events on the properties window when you have your datagrid selected. Then double click in the cell and VS will add a default event for you in the code.
EDIT:
Note that Davide Piras way of using the CellValidated event could be better for you. You may not want to call the lineCounter method if the cell is invalid.
如果不知道线路计数器或其他计数逻辑,就不可能准确给出最佳答案。如果您可以随时调用此方法并且您的计数器会更新,那么您只需从 cellValidated 事件处理程序中调用它。
Impossible to be exact and give optimal answer without knowing your linecounter or other counting logic. if you can call this method anytime and your counters get updated then you just need to call it from cellValidated event handler.