-
VS2005 combobox and databinding issues
Hello,
I have a series of comboboxes collected in a user control that are populated by a datatable. Essentially it's a stripped down query editor, so the first combobox is the available fields. Then when the field is selected, the next combobox should list available operators for the field, and the third should list available values.
The issue is even though I have a handler bindingsource.currentchanged, which sets the bindingsource.position to the selected index of the relevant combobox (in order to autofill default values across the comboboxes when the field is selected), it doesn't work for the first item in the field combobox. That is to say, if I select the second item in the field combobox, the operator combobox and value combobox populate appropriately and the first value in each is selected. However, if I go back to the first field in that combobox, the other ones are not updating, even though my bindingsource.currentchanged event is firing. Is this some sort of bug, or does anyone know if there's a workaround?
I'm new to all this databinding business, so please let me know if there's any way in which I can be more clear, or if there's any further information I can provide.
Thanks in advance
-
could you post the code for the event handler for the first combo box?
-
i have it working now, but i'm doing it in sort of a hacky way, manually firing events if the first item is selected, with a manually added handler for the selectedIndexChanged event. so that's what some of the code here is doing. but in any case:
Code:
Private Sub cmbFields_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim dv As New DataView(Me.DsSearchFields.fsp_get_fields_and_operators_for_form)
dv.RowFilter = "friendly_name='" & cmbFields.Text & "'"
Dim uniqFlds() As String = {"operator_id", "operator_text"}
Dim distinctTable As DataTable = dv.ToTable(True, uniqFlds)
cmbOperators.DisplayMember = "operator_text"
cmbOperators.ValueMember = "operator_id"
cmbOperators.DataSource = distinctTable
If cmbOperators.Text Like "*atch*" Then
cmbSearchValue.DataSource = Nothing
Else
Dim dt As New DataTable
Using cn As New SqlConnection(My.Settings.Conn)
cn.Open()
Dim cm As SqlCommand = cn.CreateCommand
cm.CommandType = CommandType.StoredProcedure
cm.CommandText = "fsp_get_autocomplete_values"
cm.Parameters.AddWithValue("@fldID", cmbFields.SelectedValue)
Dim dr As New SafeDataReader(cm.ExecuteReader)
dt.Load(dr)
End Using
cmbSearchValue.DisplayMember = "mfield"
cmbSearchValue.DataSource = dt
End If
End Sub
-
But, it does work, right?
-
yes it does but now i'm just wondering if there's a preferred way to do it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|