VB.net Option Strict,listview.items.add(itm.clone)重载

时间:2013-05-10 02:28:06

标签: vb.net listview listviewitem overload-resolution option-strict

在VB.net(2012)中,我有以下代码:

For Each itm As ListViewItem In Me.lvCustomers
    If CDbl(itm.Tag) <> customer.Id Then Me.lvMerges.Items.Add(itm.Clone)
Next

使用 Option Strict On ,我收到以下错误:

  

错误2重载解析失败,因为无法访问“添加”   用这些参数调用:       'Public Overridable Function Add(value as System.Windows.Forms.ListViewItem)As   System.Windows.Forms.ListViewItem':Option Strict On disallows   从'Object'到。的隐式转换   'System.Windows.Forms.ListViewItem'。       'Public Overridable Function Add(text As String)As System.Windows.Forms.ListViewItem':Option Strict On disallows   从'Object'到。的隐式转换   字符串 ''。

我可以做一个lvMerges.Items.Add(itm),它不会抛出错误,但是我必须从lvCustomers列表视图中删除它,我不想这样做。

有人可以解释如何在不关闭选项严格的情况下正常工作吗?

目标是将ListviewItem与所有SubItems一起复制。

1 个答案:

答案 0 :(得分:3)

您收到的错误告诉您,在Option Strict On开启时,您无法从ObjectString或{{1}进行隐式投射}}。因此,您需要进行显式转换。

ListViewItem

这有用吗?