VS2005 combobox and databinding issues


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
    Posts
    3

    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

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

  3. #3
    Join Date
    Feb 2008
    Posts
    3
    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

  4. #4
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    But, it does work, right?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  5. #5
    Join Date
    Feb 2008
    Posts
    3
    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
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

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