4
Answers

How to determine index of statusStrip Item ?

Ask a question
Rob Sobol

Rob Sobol

11y
2k
1

I am developing a WinApp in C# in Visual Studio 2010. The parent form allows the user to open child forms.
As the child forms are opened I add an entries to the statusStrip on the bottom of my form as follows:

   statusStrip1.Items.Add("<Form1>");
   statusStrip1.Items.Add("<Form2>");
   statusStrip1.Items.Add("<FormX>");

I need to get the index value of an item in that collection for subsequent RemoveAt, but all I know is the Text value of the item I added.

statusStrip1 is a System.Windows.Forms.StatusStrip
It has a collection of Items.
Not seeing where the Items.Add returns a value or index in the documentation.

When the user closes the child form, I would like to remove the entry from statusStrip1 but do not know how to determine the
index value so I can use the RemoveAt function.


I think it should be some variation of the following:

   statusStrip1.Items.Find("<Form2>");           // no error, but not sure what code does
   statusStrip1.Items.IndexOf("<Form2>")         //err on compile: invalid argument on this line, bad overload
   statusStrip1.Items.RemoveAt(0);               //works, but it removes the '0' entry, need to get the index of <Form2>

Looking forward to some helpful hints on this one.

Beers on me....:-)

Thank you in advance.
[email protected]

 


Answers (4)