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("
statusStrip1.Items.Add("
statusStrip1.Items.Add("
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("
statusStrip1.Items.IndexOf("
statusStrip1.Items.RemoveAt(0); //works, but it removes the '0' entry, need to get the index of
Looking forward to some helpful hints on this one.
Beers on me....:-)
Thank you in advance.
[email protected]
Rob SobolPosted Jun 28, 2013, 10:45 AM
Works great !
Amazing !
Thank you for working it out. The c-sharpcorner has been helpful. I will continue to use it and hopefully I will be able to give something back as my skills improve.
Have a great day!
VulpesPosted Jun 28, 2013, 10:37 AM
Try this code:
// and then look for the second item, say
Rob SobolPosted Jun 28, 2013, 9:53 AM
The end user is selecting options from a pull down menu. Each option opens a new child form. They are added in the order the end user selects to statusStrip1, potentially a different sequence each time. When they close out a particular child form the parent form receives the name of the form. I want the parent form to then remove that entry from statusStrip1.
Your solution returned an Out of Range error. I think you are parsing the string variable 'find' for a portion of itself in the line
int index = int.Parse(find.Substring(1, find.Length -2).Substring(4)) - 1;
I need to search the statusStrip1 collection to find the index that related to the string in the variable 'find' in your example.Rob
VulpesPosted Jun 28, 2013, 9:00 AM