Wednesday, February 8, 2017

Combine Projects With Combo and Listbox in Visual basic

Combobox ,Listbox adding Items , checking duplicate Data

Here is a small project or a examples useful to new comers in the field of VB. New learners can gain knowledge of Combobox , Listbox , Len , Mid ,Loop and many more functions and techniques used for further projects or in examples.

Now , I want to make a projects of inputing data from textbox and add the data to listview and combobox at the same time but
 no duplicate data to be added to the list box as well as to the combo box.

Adding the controls to the form and provide the name as you.........
 

 like and be easy to define so that you  can understand the project.

Here is an image to make as controls for the example..




Addition to project removing the data from the combobox with given data matched.

Providing the code.

You place the code in Enter to Add button
---------------------------------
  Dim i As Integer
        Dim final1 As Integer
        cmbdata.Items.Clear()
        final1 = lstdata.Items.Count
        Dim abcd As Integer
        Dim strvalue As String
        If final1 = 0 Then
            lstdata.Items.Add(txtdata.Text)
        Else
            For i = 0 To final1 - 1
                strvalue = lstdata.Items(i)
                If txtdata.Text = strvalue Then
                    abcd = 1
                Else
                    abcd = 0
                End If
            Next
            If abcd = 0 Then
                lstdata.Items.Add(txtdata.Text)
            Else
                MsgBox("Duplicate data", vbInformation)
            End If
        End If
        For i = 0 To lstdata.Items.Count - 1
            cmbdata.Items.Add(lstdata.Items(i))
        Next

-------------------------------------------

 

 

 
Above code helps to add items data to listbox and combobox at the same time. First of all code runs by counting the items data from the listbox and check the data if data are of duplicate. If it is not duplicate the add the data to the listbox. If data in listbox is valid to add then it is valid to add to the combox box.
Source code is simple to understand but tough to understand.

Thank You for your time.


Narayan Aryal
Butwal
Nepal

No comments:

Post a Comment