Page 1 of 1

Please Help With toolstrip

Posted: Mon Aug 13, 2012 8:27 pm
by 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

Re: Please Help With toolstrip

Posted: Mon Aug 13, 2012 8:58 pm
by mandai
You could use ToolStrip1.Items.RemoveAt inside a for/while loop to remove a range of items.

Re: Please Help With toolstrip

Posted: Mon Aug 13, 2012 9:05 pm
by 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

Re: Please Help With toolstrip

Posted: Tue Aug 14, 2012 12:58 pm
by M1z23R
you can use this
Code: Select all
while toolstrip.items.count > 3
Tolstrip.items.removeat(3)
End while