发生无效的强制转换异常 [英] Invalid cast exception occur
本文介绍了发生无效的强制转换异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在列表视图中显示数据
我的代码是
DtMfgDate.Value = VaccineLedgerView.SelectedItems(0).SubItems(2).Text
I want to show data in listview
my code is
DtMfgDate.Value = VaccineLedgerView.SelectedItems(0).SubItems(2).Text
推荐答案
看起来像DtMfgDate是某种日期控件,并且可能期望有效日期分配给它的值.
试试这个:
Looks like DtMfgDate is some sort of date control and would probably expect a valid date value assigned to it.
Try this:
DtMfgDate.Value = Date.Parse(VaccineLedgerView.SelectedItems(0).SubItems(2).Text)
您需要执行一些额外的编码,以确保解析的值实际上是有效日期.您也许可以考虑使用TryParse函数.
http://msdn.microsoft.com/en-us/library/497a406b.aspx [ ^ ]
祝你好运!
You need to do some extra coding to make sure that the value parsed is actually a valid date. You maybe could look into the TryParse function for that.
http://msdn.microsoft.com/en-us/library/497a406b.aspx[^]
Good luck!
尝试..
try..
DtMfgDate.Value = Convert.ToDateTime(VaccineLedgerView.SelectedItems(0).SubItems(2).Text).ToString("dd-MMM-yyyy");
这篇关于发生无效的强制转换异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文