Thursday, February 6, 2014

How to using Checkedlistbox in Visual Basic - Simple Codes

Hi,

Paste codes for using checkedlistbox control in visual basic;

Public Class Form1



    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Text = "Checkedlistbox use testing"
        'Buttons names;
        Button1.Text = "A,B,C,D,E"
        Button2.Text = "Hello World"
        Button3.Text = "Remove"
        Button4.Text = "Select"
        Button5.Text = "How is selected"
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        CheckedListBox1.Items.Clear()
        Dim datas() As String = {"A", "B", "C", "D", "E"}       'data create
        CheckedListBox1.Items.AddRange(datas)                   'inserting
        NumericUpDown1.Minimum = 0                              'adjust value in numericupdown1
        NumericUpDown1.Maximum = 4                              'adjust value in numericupdown1
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        CheckedListBox1.Items.Clear()                           'old lines clear
        CheckedListBox1.Items.Insert(0, "H")                    'lines create
        CheckedListBox1.Items.Insert(1, "E")
        CheckedListBox1.Items.Insert(2, "L")
        CheckedListBox1.Items.Insert(3, "L")
        CheckedListBox1.Items.Insert(4, "O")
        CheckedListBox1.Items.Insert(5, " ")
        CheckedListBox1.Items.Insert(6, "W")
        CheckedListBox1.Items.Insert(7, "O")
        CheckedListBox1.Items.Insert(8, "R")
        CheckedListBox1.Items.Insert(9, "L")
        CheckedListBox1.Items.Insert(10, "D")
        NumericUpDown1.Minimum = 0                              'adjust value in numericupdown1
        NumericUpDown1.Maximum = 10                             'adjust value in numericupdown1
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        CheckedListBox1.Items.RemoveAt(NumericUpDown1.Value)
    End Sub

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        CheckedListBox1.SetSelected(NumericUpDown1.Value, True)
    End Sub

    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        MessageBox.Show((CheckedListBox1.SelectedIndex + 1))
    End Sub

   
End Class




By...