如何添加日期并找到datagridview中的差异 [英] how to add date and find the difference in datagridview

查看:120
本文介绍了如何添加日期并找到datagridview中的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在开发项目库
datagridview
中应该有以下几列 发行日期截止日期|返回日期|天数罚款

发行日期应默认为今天的日期.
截止日期是必须归还图书的日期.
返回日期是实际退还书籍的日期.
我希望以天的形式表示到期日和返回日期之间的差额,因此我可以计算每人收取的罚款


I am working on a project Library
there should be following columns in datagridview
Issued date | Due Date |Returned Date | Days | Penalty

Issued date should be by default todays date.
Due date is the day on which the book has to be returned.
Returned Date is on which the books is actually returned.
I want the difference between the due date and the Returned Date in the form of days , accordingly I can calculate the penalty charged on per person
but it should be done in datagridview only.

推荐答案

如果您确实需要在datagridview中进行计算,则可以使用例如CellValidated [
If you really need to do the calculation in the datagridview, you can use for example CellValidated[^] event.

When user enters the data and it''s validated, perform the calculations you need.

Perhaps something like
Sub dgv1_CellValidated(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv1.CellValidated
   r.Cells(3).Value = System.Datetime.Parse(r.Cells(2).ToString()).Subtract(System.DateTime.Parse(r.Cells(1).ToString()).Days
End Sub


这篇关于如何添加日期并找到datagridview中的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆