DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: VS2005 combobox and databinding issues

  1. #1
    Join Date
    Feb 2008

    VS2005 combobox and databinding issues


    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

  2. #2
    Join Date
    Feb 2008
    could you post the code for the event handler for the first combo box?

  3. #3
    Join Date
    Feb 2008
    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:
        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
                Dim dt As New DataTable
                Using cn As New SqlConnection(My.Settings.Conn)
                    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)
                End Using
                cmbSearchValue.DisplayMember = "mfield"
                cmbSearchValue.DataSource = dt
            End If
       End Sub

  4. #4
    Join Date
    Apr 2007
    Sterling Heights, Michigan
    But, it does work, right?

  5. #5
    Join Date
    Feb 2008
    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
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center