Please Help With toolstrip

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
4 posts Page 1 of 1
Contributors
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

Please Help With toolstrip
muttley1968
Hello I am trying to make a tool strip clear all controls bare three so with some help came up with this
Code: Select all
  Try
            For Each tsi As ToolStripItem In ToolStrip1.Items
                If TypeOf tsi Is ToolStripButton And tsi.Text = "2" Or tsi.Text = "1" Or tsi.Name = "ToolStripSeparator3" Then
                Else
                    ToolStrip1.Items.Remove(tsi)
                End If
            Next
            For Each tsi As ToolStripItem In ToolStrip1.Items
                If TypeOf tsi Is ToolStripButton And tsi.Text = "1" Or "2" Then
                Else
                    ToolStrip1.Items.Remove(tsi)
                End If
            Next
        Catch ex As Exception
            MsgBox(ex.ToString)
        Finally
            Faves.Items.Add(ComboBox1.Text)
            Dim btnTop As Integer = 0
            For i As Integer = 0 To Faves.Items.Count - 1
                Dim btn As New ToolStripButton
                btn.Text = Faves.Items(i).ToString()
                btn.ForeColor = Color.White
                btn.BackColor = Color.FromArgb(60, 60, 60)
                btn.Tag = i
                AddHandler btn.Click, AddressOf btnclicked
                ToolStrip1.Items.Add(btn)
                btnTop += 30
            Next
        End Try
But It is not working everything loads but when I press the button for it it just brings up the message box and then excutes the finally command
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: Please Help With toolstrip
mandai
You could use ToolStrip1.Items.RemoveAt inside a for/while loop to remove a range of items.
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

Re: Please Help With toolstrip
muttley1968
Would you mind giving me a demonstration as I am not completely sure what you mean removeAT as far as I know toolstrip does not have this capability
User avatar
M1z23R
VIP - Donator
VIP - Donator
Posts: 622
Joined: Tue Sep 28, 2010 4:55 pm

Re: Please Help With toolstrip
M1z23R
you can use this
Code: Select all
while toolstrip.items.count > 3
Tolstrip.items.removeat(3)
End while
4 posts Page 1 of 1
Return to “Coding Help & Support”