How to work with RadioButton and ListBox in VB.NET

This article helps you to learn the funtionality of controls in Vb.Net.
  • 6494

In this article I am going to explain the working of two very useful controls of Vb.Net first is RadioButton and second is ListBox.

RadioButton: RadioButton is an set of two or more buttons used to present mutually exclusive options. When one button is selected, all other buttons are made to appear empty.

ListBox: ListBox is a GUI widget which allows the user to select one or more items from a list contained within a static, multiple line text box. The user clicks inside the box on an item to select it, sometimes in combination with Shift key or Control key in order to make multiple selection.

Example To Explain The Working

In this example I shows, that you have two buttons on your form and when you select the button the stored list of button will shows in the listbox on windows form.

Steps For Create The Application

  1. Open a windows application form in Vb.Net.
  2. Take two RadioButton and one ListBox.
  3. Set the Text property for both RadioBotton as StudentsNames and TeachersName.

    ar 1.gif
     
  4. Double click on StudentsName RadioButton and write this code.

    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
        ListBox1.Items.Clear()
        ' Add some string data to the source data listbox.
        ListBox1.Items.Add("NeKeta Argrow")
        ListBox1.Items.Add(
    "Adam Barr")
        ListBox1.Items.Add(
    "Bonnie L. Skelly")
        ListBox1.Items.Add(
    "Rob Caron")
        ListBox1.Items.Add(
    "Angela Barbariol")
    End Sub
     
  5. Double click on TeachersName RadioButton and write this code.

    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
        ListBox1.Items.Clear()
        ' Add some string data to the source data listbox.
        ListBox1.Items.Add("kjju")
        ListBox1.Items.Add(
    "hdjjkl")
        ListBox1.Items.Add(
    "dffdfrf")
        ListBox1.Items.Add(
    "jjkjoknfa")
        ListBox1.Items.Add(
    "jjiokpppoplp")
    End Sub

    2.gif

     
  6. Run the Application, if you select the StudentsName button the students record will display in ListBox, and if you select the TeachersName button the teachers record will display.

    ar 3.gif
    ar 4.gif

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.