• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 388
  • Last Modified:

Access toolstrip items from code behind

I have a vb.net winforms application that has many forms.  I use a bindingnavigator and on that is a label (toolstriplabel).  I have a module which has a public function that I want to update the label from.  Since this is used by multiple forms I need someway of doing this..

What is the correct syntax for to do this?  An example would help greatly.
  • 2
1 Solution
I'm writing my first .Net app at the moment, so apologies if this proves to be utter nonsense...

Could you create a string property in the BindingNavigator class that you could get/set as you need?

        /// <summary>
        /// Holds the selected LabelText for the BindingNavigator.
        /// </summary>
        private string labelText;
        public string LabelText
            get { return this.labelText; }
            set { this.labelText = value; }

Open in new window

Set the BindingNavigator's LabelText property from your function (once you have created an object reference to the BindingNavigator).  You could then refresh the text in your label by getting the BindingNavigator's LabelText property.

Hope this helps - if not, apologies!
K-9Author Commented:
I was able to resolve it with this..

Function ChangeToolStripLabel(ByVal Process As String)
        Dim currentForm As Form = Form.ActiveForm

        ' Loop through all the controls on the active form. 
        Dim i As Integer
        For i = 0 To currentForm.Controls.Count - 1
            If currentForm.Controls.Item(i).Name = "BindingNavigator1" Then

                Dim c As Control
                Dim ts As ToolStrip = currentForm.Controls.Item(i)
                For Each itm As ToolStripItem In ts.Items
                    If itm.Name = "tsStatus" Then
                        itm.Text = "Status: " & Process
                    End If

            End If
        Next i

    End Function

Open in new window

K-9Author Commented:
Able to resolve it with this code.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now