This is the code:
private void Lightnings_Mode_Load(object sender, EventArgs e)
{
this.Size = new Size(416, 506);
this.Location = new Point(23, 258);
listBoxIndexs();
this.listBox1.SelectedIndex = 0; // This will make the listBox when showing it first time first item to be already selected !!!!!!
}
private void listBoxIndexs()
{
for (int i = 0; i < Form1.lightningsRegions.Count; i++)
{
listBox1.Items.Add(Form1.lightningsRegions[i]);
}
}
private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
item = listBox1.SelectedItem.ToString();
this.f1.PlayLightnings();
f1.pdftoolsmenu();
if (item != null && !pdf1.Lightnings.Contains(item.ToString()))
{
pdf1.Lightnings.Add(item.ToString());
}
}
Im using the variable item in two places in Form1.
Once to extract the string and play the numbers inside and once to add item to the List Lightnings.
In the first time for playing the numbers i want it to be:
this.listBox1.SelectedIndex = 0;
Since i want to be able to play already the first item once i clicked a button and showed/opened the listBox.
In the second place where im adding the item to the Lightnings List i want that it will add the item only if i clicked first on any item.
Since i did :
this.listBox1.SelectedIndex = 0;
It will add item automatic to Lightnings once i show/open the listBox
I need it to be added to the List only if i click first an item in the other hand i also want to be selectedindex = 0 since i want it to be selected so i can play it.
So how can i separate between the SelectedIndex = 0 for playing and for adding the item to the List ?
If I understand correctly, you can simply add a flag.
The flag will then stay true until you explicitly change it to false, so you can control when items should be added or not.