List box detects that iteam is being selected

-1

I want to double click on the item in the listbox, when start it does an action, when I double click on any other item it does another action.

Code:

//btnWhenClicked
private void btnWhenStart_Click(object sender, EventArgs e)
{
    ListItemsBox.Items.Add("When Start"); //é este iteam que eu quero que detect
    btnWhenStart.Hide();
    string path = AppDomain.CurrentDomain.BaseDirectory.ToString() + "MyTest.txt";

    //Create And Write File
    if (!File.Exists(path))
    {
        using (StreamWriter sw = File.CreateText(path))
        {
            sw.WriteLine("using System;");
            sw.WriteLine("using System.Collections.Generic;");
            sw.WriteLine("using System.Linq;");
            sw.WriteLine("using System.Text;");
            sw.WriteLine("using System.Threading.Tasks;");

            sw.WriteLine("\r\n namespace CMD");
            sw.WriteLine("{");
            sw.WriteLine("    class Program");
            sw.WriteLine("    {");
            sw.WriteLine("        static void Main(string[] args)");
            sw.WriteLine("        {");
            sw.Close();
        }

    }



}

//delete ListItemsBox Selected Item
private void ListItemsBox_DoubleClick(object sender, EventArgs e)
{
    string path = AppDomain.CurrentDomain.BaseDirectory.ToString() + "MyTest.txt";
    DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete this item?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
    if (dialogResult == DialogResult.Yes)
    {
        ListItemsBox.Items.Remove(ListItemsBox.SelectedItem);
    }
    else if (dialogResult == DialogResult.No)
    {

    }
}
    
asked by anonymous 09.08.2016 / 11:11

1 answer

0

I've been able to figure out how to do it is simpler than it sounds

private void ListItemsBox_DoubleClick(object sender, EventArgs e)
{
    string path = AppDomain.CurrentDomain.BaseDirectory.ToString() + "MyTest.cs";
    if (ListItemsBox.SelectedItem.Equals("When Start"))
    {
        DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete this item?All items will be deleted including all files!", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
        if (dialogResult == DialogResult.Yes)
        {
            ListItemsBox.Items.Clear();
            File.Delete(path);
            btnWhenStart.Show();
        }
        else if (dialogResult == DialogResult.No)
        {

        }
    }
    else
    {
        DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete this item?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
        if (dialogResult == DialogResult.Yes)
        {
            ListItemsBox.Items.Remove(ListItemsBox.SelectedItem);
        }
        else if (dialogResult == DialogResult.No)
        {

        }
    }

}
    
09.08.2016 / 12:40