Convert object to ListViewItem

為{幸葍}努か 提交于 2020-01-06 12:52:12

问题


I am trying to convert my Winforms application to WPF format, I am trying to convert the double click of my listview at the moment. I have done this so far:

private void listView1_DoubleClick(object sender, MouseButtonEventArgs e)
{
ListViewItem item = this.listView1.SelectedItems[0];
if (item.Tag != null)
{
    ControllerInfo controllerInfo = (ControllerInfo)item.Tag;

    if (controllerInfo.Availability == Availability.Available)
      {
        if (controllerInfo.IsVirtual)
         {
            this.controller = ControllerFactory.CreateFrom(controllerInfo);
            this.controller.Logon(UserInfo.DefaultUser);
            listView1.Items.Clear();
            listView1.Items.Add(item);
            EnableControllerFunctionality();
         }

    else //real controller
    {
       if (MessageBox.Show("This is NOT a virtual controller, do you really want to connect to that?","Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
     {
       this.controller = ControllerFactory.CreateFrom(controllerInfo);
       this.controller.Logon(UserInfo.DefaultUser);
       listView1.Items.Clear();
       listView1.Items.Add(item);
       EnableControllerFunctionality();
      }
     }
    }
 else
  {
    MessageBox.Show("Selected controller not available.");
   }
 }

The problem is with the first line :

ListViewItem item = this.listView1.SelectedItems[0];

stating 'cannot implicitly convert from object to listviewitem. An explicit conversion exists I have been trying to find this conversion but to no avail. I feel as though I am missing something key.

来源:https://stackoverflow.com/questions/23654281/convert-object-to-listviewitem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!