Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9055723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:01:32+00:00 2026-06-16T14:01:32+00:00

This is the code: private void Lightnings_Mode_Load(object sender, EventArgs e) { this.Size = new

  • 0

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 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T14:01:33+00:00Added an answer on June 16, 2026 at 2:01 pm

    If I understand correctly, you can simply add a flag.

    bool allowItemAdding;
    
    private void Lightnings_Mode_Load(object sender, EventArgs e)
    {
        allowItemAdding = false; //setting false here because *sometimes* Load event is called multiple times.
    
        this.Size = new Size(416, 506);
        this.Location = new Point(23, 258);
        listBoxIndexs();
        this.listBox1.SelectedIndex = 0;  
        allowItemAdding = true; //set flag to true after selecting the index initially
    }
    
    private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
    {          
         item = listBox1.SelectedItem.ToString();
         this.f1.PlayLightnings();
         f1.pdftoolsmenu();
         if (allowItemAdding)
         {
             if (item != null && !pdf1.Lightnings.Contains(item.ToString()))
             {
                 pdf1.Lightnings.Add(item.ToString());             
             }
         }
    }
    

    The flag will then stay true until you explicitly change it to false, so you can control when items should be added or not.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code: private void comboBoxFontSize_SelectedIndexChanged(object sender, EventArgs e) { rtbResults.Font.Size = Convert.ToInt32(comboBoxFontSize.SelectedItem); } ...generates
I have this code: private void timer1_Tick(object sender, EventArgs e) { #region BaseAddress Process[]
I have the following code: private void _DoValidate(object sender, DoWorkEventArgs e) { this.BeginInvoke(new MethodInvoker(()
I am using this code: private void Form1_Load(object sender, EventArgs e) { } private
i have this code: private void aboutToolStripMenuItem_Click(object sender, EventArgs e) { this.WindowState = FormWindowState.Minimized;
I have this code private void FrmNovedadMedidas_SelectionChangeCommitted(object sender, EventArgs e) { ComboBox c =
I have this code: private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e) { if (listBox1.SelectedItem !=
In this code private void btnConnect_Click(object sender, EventArgs e) { string localHost = 192.168.10.3;
I have a strange problem. I have this code: private void button1_Click(object sender, EventArgs
I have this code: private void ToLocalSiteOnlyToolStripMenuItem_Click(object sender, EventArgs e) { if (buttonSwitch ==

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.