By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,333 Members | 1,060 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,333 IT Pros & Developers. It's quick & easy.

filter datatable for combox datasource

P: n/a
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 ?
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Daylor,

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

I hope this helps?

Cor

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 ?

Nov 21 '05 #2

P: n/a
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

"Daylor" <do*************@nomail.com> wrote in message
news:cg**********@news2.netvision.net.il...
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 ?

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.