filter datatable for combox datasource

  • Thread starter Thread starter Cor Ligthert
  • Start date Start date
C

Cor Ligthert

Daylor,

A combobox is not a datagrid,
It needs at least a displaymember

I hope this helps?

Cor
 
hi.

i have 2 combobox on form.

after i load the form.

when i select the first combobox , i want to filter the datatable that
attached to the second combobox.

i wrote :

--------------
on SelectedIndexChanged event

combo2.DataSource = myDataTable.Select ( field=5)

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

what i get is , the combo is filled with string of "System.Data.DataRow".



what im missing here ?
 
Here is how I am doing that. I am not using databinding though...

Private Sub cbo1_SelectionChangeCommitted(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles cbo1.SelectionChangeCommitted

BindCBO2(CType(cbo1.SelectedItem, ListBoxItem).Data.ToString)

End Sub

Private Sub BindCBO2(ByVal value1 As String)

cbo2.SelectedIndex = -1

Dim dv As DataView = DAL.GetData.DefaultView
dv.RowFilter = "SomeField = '" & value1 & "'"


cbo2.BeginUpdate()
cbo2.Items.Clear()
For Each drv As DataRowView In dv
cbo2.Items.Add(New ListBoxItem(drv("CBO2_DATA").ToString,
drv("CBO2_TEXT").ToString))
Next
cbo2.EndUpdate()


End Sub

' helper class...
Public Class ListBoxItem

Private listItemData As Object
Private listItemText As String

' This is what is displayed in the ComboBox drop-down
Public Overrides Function ToString() As String
Return listItemText
End Function

Public Sub New(ByVal itemData As Object, ByVal itemText As String)

listItemData = itemData
listItemText = itemText
End Sub

Public ReadOnly Property Data() As Object
Get
Data = listItemData
End Get

End Property

Public ReadOnly Property Text() As String
Get
Text = listItemText
End Get

End Property

End Class

HTH,
Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top