none
Using one item in two forms RRS feed

  • Question

  • hi all,

    i am dealing with more than one form. But i got stuck in a place where i want to show the selected item in a list in one form to a label text in another form. Selected item in the list box should show as a heading in the next form

    thanks in advance

    Monday, August 28, 2017 7:00 AM

Answers

  • Hi AbhinandNandu,

    According to your description, you want to use listbox.selectitem context in the form that showing as heading in the another form, am I right?

    If yes, please refer to the following code.

    Form 1:

     Private Sub Form6_Load(sender As Object, e As EventArgs) Handles MyBase.Load
                    ListBox1.Items.Add("Show Form 1")
            ListBox1.Items.Add("Show Form 2")
            ListBox1.Items.Add("Show Form 3")
    
    
        End Sub
    Public context As String
        Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
            If ListBox1.Items.Count > 0 Then
                context = ListBox1.SelectedItem.ToString()
                Dim f As New Form7(context)
                f.Show()
            End If
        End Sub

    Form 2:

     Public _title As String
        Private Sub Form7_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.Text = _title
        End Sub
        Public Sub New(title As String)
            _title = title
            ' This call is required by the designer.
            InitializeComponent()
            ' Add any initialization after the InitializeComponent() call.
        End Sub

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by AbhinandNandu Wednesday, August 30, 2017 6:42 AM
    Tuesday, August 29, 2017 4:17 AM
    Moderator
  • actually i dont want to show it as a tittle of the form but i want to display that item as label text as below

    Where you are going to display it doesn't matter, but how you are using it will control what you need to do.

    If the value is available when the form is created and will not change, then pass it in the constructor as shown in example (2) of the reference I provided.

    If it is not available when the form is created, or if there is some other reason that it cannot be passed when the form is created, then instead you should pass a reference either to the control that contains the value, or the form that contains the control that contains the value, so it can be retrieved as required. If it might change and needs to be updated when it changes, then you can use messaging.


    • Edited by Acamar Wednesday, August 30, 2017 6:10 AM sp
    • Marked as answer by AbhinandNandu Wednesday, August 30, 2017 6:33 AM
    Wednesday, August 30, 2017 6:10 AM

All replies

  • i am dealing with more than one form. But i got stuck in a place where i want to show the selected item in a list in one form to a label text in another form. Selected item in the list box should show as a heading in the next form

    2, 3, 4 or 5 here:  https://vbdotnetblog.wordpress.com/forms/

    Which one you use depends on how the forms are arranged and how the data is being updated.  If the value exists when the second form is created and doesn't change, then simply pass it in the constructor to the new form (2).  If the value needs to be copied in when something happens on the second form, then pass the control that contains that value to the constructor of the second form, and access the value from the control as required (2) or get a reference to the main form and use that reference to access the control on that form and the property in the control from the second form (3).  If the value needs to be updated in the second form when it changes on the first form, use messaging (5).  Or some combination of these.


    • Edited by Acamar Monday, August 28, 2017 7:15 AM sp
    Monday, August 28, 2017 7:14 AM
  • Hi AbhinandNandu,

    According to your description, you want to use listbox.selectitem context in the form that showing as heading in the another form, am I right?

    If yes, please refer to the following code.

    Form 1:

     Private Sub Form6_Load(sender As Object, e As EventArgs) Handles MyBase.Load
                    ListBox1.Items.Add("Show Form 1")
            ListBox1.Items.Add("Show Form 2")
            ListBox1.Items.Add("Show Form 3")
    
    
        End Sub
    Public context As String
        Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
            If ListBox1.Items.Count > 0 Then
                context = ListBox1.SelectedItem.ToString()
                Dim f As New Form7(context)
                f.Show()
            End If
        End Sub

    Form 2:

     Public _title As String
        Private Sub Form7_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.Text = _title
        End Sub
        Public Sub New(title As String)
            _title = title
            ' This call is required by the designer.
            InitializeComponent()
            ' Add any initialization after the InitializeComponent() call.
        End Sub

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by AbhinandNandu Wednesday, August 30, 2017 6:42 AM
    Tuesday, August 29, 2017 4:17 AM
    Moderator
  • actually i dont want to show it as a tittle of the form but i want to display that item as label text as below

    • Marked as answer by AbhinandNandu Wednesday, August 30, 2017 6:42 AM
    • Unmarked as answer by AbhinandNandu Wednesday, August 30, 2017 6:42 AM
    Wednesday, August 30, 2017 5:35 AM
  • actually i dont want to show it as a tittle of the form but i want to display that item as label text as below

    Where you are going to display it doesn't matter, but how you are using it will control what you need to do.

    If the value is available when the form is created and will not change, then pass it in the constructor as shown in example (2) of the reference I provided.

    If it is not available when the form is created, or if there is some other reason that it cannot be passed when the form is created, then instead you should pass a reference either to the control that contains the value, or the form that contains the control that contains the value, so it can be retrieved as required. If it might change and needs to be updated when it changes, then you can use messaging.


    • Edited by Acamar Wednesday, August 30, 2017 6:10 AM sp
    • Marked as answer by AbhinandNandu Wednesday, August 30, 2017 6:33 AM
    Wednesday, August 30, 2017 6:10 AM
  • THANKS for your help

    i am able to do it. i just want your support in one more thing.

    normally windows forms will have maximize, minimize and close icons in the top write i just wnat to remove those icons from my forms. i am able to remove maximize and minimize icons but not the close icon how i can do that. 

    Wednesday, August 30, 2017 6:41 AM
  • i am able to do it. i just want your support in one more thing.

    Please ask your new question in a new post, with a new title that refers to the question.
    Wednesday, August 30, 2017 8:40 AM
  • i got the solution

    Wednesday, August 30, 2017 12:42 PM