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
 

Detect for multiple values in a ComboBox.

Author: DevASP
Download Source Code : 311_ComboBox.zip

This article is about how to detect for multiple values in a ComboBox control.

ComboBox control is combination of two controls the TextField and ListBox. So ComboBox have the functionality of both controls TextBox as well as the ListBox control

 

  • Steps you will do.
  • Start visual studio and create a new window application.
  • Set the following properties of the Form control.

Name = frmMain, Text   = Detect For Multiple Values.

 

  • Drop a ComboBox control on the Form and set the following properties.

Name = testCombo, Text = “”, DropDrownStyle = DropDrownList

 

  • Drop a TextField and set the following properties.

Name = tbAdd, Text = “”

 

  • Drop a Button control and set its following properties.

Name = btAdd, Text = Add to ComboBox

 

  • Drop a Lablel  control on the form. Set its Text property to “”.
  • Drop a ErrorProvider Control to the designer and set its name to “errorMessage”.

Your application design has been completed. Now write the following code in the click event of the button to add the textbox value in the ComboBox.

 

If tbadd.Text.Equals("") Then

   displayMessage("Empty Field!")

   Return

End If

 

Dim index As Integer = _ testCombo.FindStringExact(tbadd.Text)

 

 

If index >= 0 Then

 

    tbadd.Text = ""

    displayMessage("Duplicate")

    tbadd.Focus()

 

Else

    testCombo.Items.Add(tbadd.Text)

    displayMessage("")

 

End If

·         Write the following function to display the error message.

Private Sub displayMessage(ByVal message As String)

 

  errorMessage.SetError(tbadd, message)

 

If message.Equals("Duplicate") Then

 

    Label1.Text = "Duplicate Vlaue"

 

ElseIf message.Equals("Empty Field!")_

 

Then

 

   Label1.Text = "Enter Text In Field. "

 

Else

 

Label1.Text = "Name: " & _ testCombo.Text() & "has been added."

 

End If

 

End Sub

 

Now run your application enter some text in the textbox and click the button to add this text into the ComboBox. If the entered text already exists the ErrorProvider will be set and you will get the message.

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How To Disable Close Button in Windows Form

Disclaimer - Privacy
© 2002-2017 DevASP.net