i want to hide the other button when i click the btnSnacks/btndrinks
buttons: btndrinks, btnSnacks
table: tbldrinks, tblSnacks [I use MS access]
heres the code that i tried:
~[i use the same code in btnSnacks, i just replace the database with tblSnacks]

 Private Sub btndrinks_Click(sender As System.Object, e As System.EventArgs) Handles btndrinks.Click
        btndrinks1()

    End Sub

Sub btndrinks1()

        Dim CMD As OleDb.OleDbCommand = New OleDb.OleDbCommand("Select * from tbldrinks", con)
        Dim rd As OleDbDataReader = CMD.ExecuteReader()
        If rd.HasRows() Then
            Dim pos As New Point(5, 5)
            Dim sz As New Size(100, 100)
            Do While rd.Read()

                Dim btn As New Button
                btn.Name = "" & rd.Item("nod").ToString()
                btn.Text = btn.Name
                btn.Size = sz
                btn.Location = pos

                ListBox1.Controls.Add(btn)

                AddHandler btn.Click, AddressOf clickMe

                Dim xpos As Integer
                Dim i As Integer
                Math.DivRem(i, 2, xpos)

                If (xpos = 0) Then
                    pos.X = btn.Left + btn.Width + 5
                Else
                    pos.X = 5
                    pos.Y = btn.Top + btn.Height + 5
                End If

            Loop

        End If

        rd.Close()
        CMD.Dispose()
    End Sub

Hi

Not sure I understand your question. Are you saying that if you click btnSnacks then you want to hide btnDrinks and if you click btnDrinks you want to hide btnSnacks? Although how that would work I am not sure as one will be visible while the other would not.

Can you provide some more information please.

@djjeavons, yes, i want to hide the buttons in btnSnacks when i click btnDrinks and vice versa.
i have list of different kinds of drinks in
tbldrinks, in the Listbox1 [where i add the buttons] the list in tbldrinks needs to be view in LIstbox1 but it should be button.
the buttons in Listbox1 came from the database
[help me plz]

@djjeavons, yes, i want to hide the buttons in btnSnacks when i click btnDrinks and vice versa.

But if you click btnSnacks and hide btnDrinks then how will you click btnDrinks to do the vice versa bit?

As for hiding a button, simply set its Visible property to False, so when you click btnSnacks you would do btnDrinks.Visible = False

btnSnacks :[focaccia bread and focaccia bread II]
btnDrinks : [maria theresaa fav]
when i click btnSnacks after the btnDrinks, the record show the same button as btnSnacks[focaccia bread and focaccia bread II] , but when i click btndrinks after btnSnacks, the 1st button is from btndrinks then the other one came from btnSnacks[maria theresas fav and focaccia bread II] [in my observation i think the button is hiding to another button]
heres the screenshot of the form

Attachments 10.jpg 27 KB 12.jpg 28.09 KB

@djjeavons , what i really want to hide is the Big button as you can see in the photo above

Hi

If you know the name of the button when you create it you can access it and set it's visibility to False or even remove it from the list.

    Dim ctl As Control = ListBox1.Controls("NameOfControl")
    ctl.Visible = False

To remove a single control use: ListBox1.Controls.Remove(ctl)

Or alternatively, each time you click Drink or Snacks then remove all controls from the list before adding them again?

    For controlIndex As Integer = (ListBox1.Controls.Count - 1) To 0 Step -1
        ListBox1.Controls.RemoveAt(controlIndex)
    Next

@djjeavons , thank you so much,i really appreciate it, i will try your code

@djjeavons sorry ,i got it now. the 1st code that you give me is not working so i tried the other one and it works now. Sorry i got confused. anyway thank you so much, you are a great help :D

This question has already been answered. Start a new discussion instead.