0

All,

I need to enable multi columns since I want to add "Last Modified date" next to the file name. I was able to get the listbox to show the results from the search without showing the path by using:

  listView1.Items.Add(Path.GetFileNameWithoutExtension(file));

My issue now is that when I change Listbox to Listview I get an error on this line:

    string fullFileName = selectedFiles[listView1.SelectedIndex];

    Process.Start(fullFileName);


  Error CS1061  'ListView' does not contain a definition for 'SelectedIndex' and no extension method 'SelectedIndex' accepting a first argument of type 'ListView' could be found (are you missing a using directive or an assembly reference?) SearchSC    C:\Users\laswgonzalez\Desktop\VB Projects\SearchSC\SearchSC\Form1.cs    56  Active

Here's the code:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.IO;
    using System.Diagnostics;



    namespace SearchSC
     {
         public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    // Global Variable
    List<string> selectedFiles = new List<string>();


    private void button1_Click(object sender, EventArgs e)
    {
        listView1.Items.Clear();
        string[] files = Directory.GetFiles("T:\\SC",
        "*.*",
        SearchOption.AllDirectories);
        {
            foreach (string file in files)
            {
                if (Path.GetFileName(file).Contains(t_search.Text))
                {

                    listView1.Items.Add(Path.GetFileNameWithoutExtension(file));
                    selectedFiles.Add(file);

                    int ttl = listView1.Items.Count;
                    textBox1.Text = Convert.ToString(ttl);
                    label1.Text = "Results Found";
                }
            }
        }


    }

    private void listView1_DoubleClick(object sender, EventArgs e)
    {

        string fullFileName = selectedFiles[listView1.SelectedIndex];

        Process.Start(fullFileName);

    }
    // label text
    private void Form1_Load(object sender, EventArgs e)
    {
        label1.Text = "";
    }


}

}

Any thoughts? I really appreciate the help.

1 Answers1

0

You're looking for the SelectedIndices property.

https://msdn.microsoft.com/en-us/library/system.windows.forms.listview.selectedindices(v=vs.110).aspx

James
  • 66
  • 2