Ngqulunga Ответов: 2

Мой ComboBox не заполнения на дисплее настоящее время он работает и элемент значения. Некоторые любезно советуют, что я здесь сделал не так.


клиентский код
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


Код Класса
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


Что я уже пробовал:

Попробовал заполнить эту информацию в gridview, она работает нормально, то есть в objectList есть информация, но combobox просто пуст.
Вот мои данные сетки.
SuppID  SuppName
1	Rainbow Chicken			
2	Evergreen Veggies			
3	Albany			
4	Jabula Supermarket

2 Ответов

Рейтинг:
4

Ngqulunga

Проблема была решена.

'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


'Код Загрузки Формы

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


Рейтинг:
0

Karthik_Mahalingam

попробуйте вот так, снять петлевую часть

cmbSupplierList.ValueMember = "SupplierID"
cmbSupplierList.DisplayMember = "SupplierName"
cmbSupplierList.DataSource = objSList


Graeme_Grant

Да, важно установить свойства в том порядке, который использовал Karthik Bangalore. cmbSupplierList.DataSource = objSList выполняет привязку...

Ngqulunga

Спасибо @Karthik Bangalore, @Graeme_Grant за подсказки

Karthik_Mahalingam

крутой