Click here to Skip to main content
16,012,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Client Code
Dim objSupplier As New csSupplier
Dim objSList As New List(Of csSupplier)

objSList = objSupplier.GetSupplierList()
'Just Testing the objectList if it has data, and it displays fine on a gridview.
DataGridView2.DataSource = objSList

'Populating the combobox.
cmbSupplierList.DisplayMember = "Test"
For Each x As csSupplier In objSList
    Me.cmbSupplierList.DataSource = objSList
    Me.cmbSupplierList.DisplayMember = x.SupplierName
    Me.cmbSupplierList.ValueMember = x.SupplierID
Next


Class Code
Public Property SupplierID() As Integer
    Get
        Return _supplierID
    End Get
    Set(value As Integer)
        _supplierID = value
    End Set
End Property

Public Property SupplierName() As String
    Get
        Return _sname
    End Get
    Set(value As String)
        _sname = value
    End Set
End Property

'Get list of Suppliers
Public Function GetSupplierList() As List(Of csSupplier)
    Dim objDal As New csSQLDALVB
    Dim objList As New List(Of csSupplier)
    Using dr As IDataReader = objDal.executespreturndr("GetListOfSuppliers")
        While (dr.Read)
            Dim par As New csSupplier
            par.SupplierID = dr.GetInt32(0)
            par.SupplierName = dr.GetString(1)
            objList.Add(par)
        End While
    End Using
    Return objList
End Function


What I have tried:

Tried populating this info in a gridview, its working fine meaning the objectList has info but the combobox is just empty.
Here is my grid Data.
SuppID  SuppName
1	Rainbow Chicken			
2	Evergreen Veggies			
3	Albany			
4	Jabula Supermarket
Posted
Updated 16-Aug-17 11:00am

try like this, remove the looping part

cmbSupplierList.ValueMember = "SupplierID"
cmbSupplierList.DisplayMember = "SupplierName"
cmbSupplierList.DataSource = objSList
 
Share this answer
 
v2
Comments
Graeme_Grant 16-Aug-17 5:48am    
Yes, it is important to set the properties in the order that Karthik Bangalore has used. cmbSupplierList.DataSource = objSList executes the binding...
Ngqulunga 16-Aug-17 16:59pm    
Thanks @Karthik Bangalore, @Graeme_Grant for giving the Hints
Karthik_Mahalingam 17-Aug-17 0:37am    
cool
The problem has been solved.
'Combobox Client code
<pre>    Private Sub cmbSupplierList_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cmbSupplierList.SelectedIndexChanged
        'Looping into a suppliers list object
        For Each x As csSupplier In objSList '
            'Mapping in supplier ID into supplier name
            If cmbSupplierList.SelectedItem = x.SupplierName Then
                lbltest.Text = x.SupplierID
                grdSupplierStock.DataSource = objStock.GetIngredientsBySupplier(x.SupplierID)
            End If
        Next
    End Sub


'Form Load Code

Private Sub InvetoryDetails_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim objSupplier As New csSupplier
Dim objSList As New List(Of csSupplier)

    objSList = objSupplier.GetSupplierList() 'Assigning an array list returned by a method in Class Objec List
    'Looping into a suppliers list object
    For Each x As csSupplier In objSList
        cmbSupplierList.Items.Add(x.SupplierName) 'Populating supplier name in combobox
    Next
End Sub
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900