计算datagridview中两个日期值之间的时间跨度

时间:2014-07-20 18:32:11

标签: vb.net date datagridview timespan

我在DataGridView中有2个日期列,其中包含日期。我需要计算这些日期之间的time span,并在用户点击该特定行时显示它们。我读了timespan结构,发现它使用格式#date2# - #date1#。这是我的程序中的相关代码:

Dim Timespan span
span = FaultsDataGridView.SelectedRows(0).Cells(4).Value - FaultsDataGridView.SelectedRows(0).Cells(3).Value

第5个(索引4)列中的日期始终在第4个(索引3)列中的日期之后。我已经确定了这一点。但是,我收到ArgumentOutOfRange Exception,其中包含以下消息:

  

指数超出范围。必须是非负数且小于collection.Parameter name:index。

的大小

有谁知道为什么会这样?

1 个答案:

答案 0 :(得分:0)

使用(DirectCast(DataGridView([columnindex],e.Row.Index).Value,DateTime)。非常感谢您的投入,伙计们。