0

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.

H.B.
  • 166,899
  • 29
  • 327
  • 400
  • Ever heard of MVVM? If not please do. – Sriram Sakthivel May 14 '14 at 12:10
  • 1
    Delete all that horrible code and use proper DataBinding. WPF is not winforms. – Federico Berasategui May 14 '14 at 12:21
  • 1
    Read [this](http://msdn.microsoft.com/en-us/library/ms752347.aspx) and [this](http://msdn.microsoft.com/en-us/library/ms742521.aspx), and as mentioned MVVM may be of interest. – H.B. May 14 '14 at 12:43
  • Might help .please use databinding and mvvm , Once you get understand about its pretty easy thing. [Mvvm and Wpf from scrath](http://stackoverflow.com/questions/1405739/mvvm-tutorial-from-start-to-finish) .For ur help ListViewItem item = sender as ListViewItem; – Eldho May 14 '14 at 13:37
  • I have read the suggested pages, and tried the above line, debugging has shown me that item remains null. I still don't understand can anyone advise? – MechatronicsStudent May 19 '14 at 13:50

0 Answers0