Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Implementing ListBox Basics Using VB.Net 2.0

Author: Zunnair
Download Source Code : 755_ListBox.zip

In this article I Will Explain How You Can Interact With List Box Using Vb.Net .This Article for the beginners.

In This Article I  will show you how to

 

1: add to a listbox control

2: Delete from a listbox

3: Check an item exists before adding or deleting.

 

This application shows you how to add and delete items from a listbox at runtime. To begin, enter some text into the textbox. Then choose your option (add the text to the listbox or delere it from the listbox. Then, press Do It! As long as you have passed my validation you should be informed that the item already exists. be informed that the item does not exist or the listbox has one more or one less item.

 

To create List box  Application Follow Some Steps and Understand Code Below.

 

1. Create new application Using File menu and Choose vb.net project.

Now you will see the form Open in your application.

 

2. Now Drag the list box from toolbox .Named it as LBX DEMO.

 

3-Now Add The two Radio Buttons one for delete and other for add Purpose.

     

4- Add  One button to perform action and Double click on button to generate Click Event against it.

Write the code below in button Click Event Routine.

    Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click

        Dim sTheText As String

 

        If txtTheText.TextLength = 0 Then

            txtTheText.Focus()

            iError_Count = iError_Count + 1

            sErrors = "* You did not enter any text" & vbCrLf & ""

        End If

        If rbtnAdd.Checked = False And rbtnDel.Checked = False Then

            iError_Count = iError_Count + 1

            sErrors &= "* You did not pick a radio button"

        End If

 

        If iError_Count > 0 Then

            lblErrors.Text = sErrors

        Else

            lblErrors.Text = ""

            If rbtnAdd.Checked = True Then

                sTheText = Trim(txtTheText.Text)

                If lbxDemo.Items.Contains(sTheText) = True Then

                    MessageBox.Show("That value is already in the listbox.", "Error")

                    txtTheText.Clear()

                    txtTheText.Focus()

                Else

                    lbxDemo.Items.Add(sTheText)

                    txtTheText.Clear()

                    txtTheText.Focus()

                End If

            End If

            If rbtnDel.Checked = True Then

                sTheText = Trim(txtTheText.Text)

                If lbxDemo.Items.Contains(sTheText) = True Then

                    lbxDemo.Items.Remove(sTheText)

                    txtTheText.Clear()

                    txtTheText.Focus()

                Else

                    MessageBox.Show("That value is not in the listbox.", "Error")

                    txtTheText.Clear()

                    txtTheText.Focus()                    

                End If

            End If

        End If

        iError_Count = 0

        sErrors = ""

 

        If lbxDemo.Items.Count = 0 Then

            rbtnDel.Visible = False

        Else

            rbtnDel.Visible = True

        End If

 

    End Sub

 

Now Built and run the Project You will see the List Box Addition And Deletion of text item is So Simple. The source Code is given by this article for your Complete Understanding. Just run it you can understand how easily we can create it.  

Article Comments
may i know coding for
listview,combobox,list box,panel,datagrid,timer,radiobutton,checkbos,groupbox,mainmenu

Posted on 5/26/2009 9:38:24 AM by vino

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Working with Summary Box With Header Image Buttons using VB.Net 2.0

Disclaimer - Privacy
© 2002-2017 DevASP.net