cascading combobox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pmcguire

    #1

    cascading combobox

    I have 2 bound ComboBoxes. I want the datasource of the second to be limited
    by the selection made in the first. I can do this by responding to the
    SelectionIndexC hanged event on the first, but this results in the
    BindingContext' s Current.Row.Row state becoming 'Modified' whenever the
    BindingContext position changes. What is the RIGHT way to go about this?

    Thanks,
    --
    Pat
  • Ken Tucker [MVP]

    #2
    Re: cascading combobox

    Hi,

    Bind the second combobox to a dataview. Use the dataview.rowfil ter
    method to only show the right records.

    Ken
    ---------------
    "pmcguire" <pmcguire@discu ssions.microsof t.com> wrote in message
    news:4C75C8A0-A0E6-4FB4-AF17-CD6732024696@mi crosoft.com...
    I have 2 bound ComboBoxes. I want the datasource of the second to be
    limited
    by the selection made in the first. I can do this by responding to the
    SelectionIndexC hanged event on the first, but this results in the
    BindingContext' s Current.Row.Row state becoming 'Modified' whenever the
    BindingContext position changes. What is the RIGHT way to go about this?

    Thanks,
    --
    Pat


    Comment

    • pmcguire

      #3
      Re: cascading combobox

      Hmm. I don't really understand.

      You mean use a filtered DataView as the second ComboBox's DataSource? I am
      already doing that. The problem isn't obtaining the list of values needed
      for the ComboBox, the problem is that I want to bind the SelectedValue of the
      two ComboBoxes to columns in another table. When PositionChanged fires,
      Combo1 and Combo2 both get new values; however, in general, the value Combo2
      gets from its currency manager is not yet present in its list, so after
      Combo1_Selectio nIndexChanged fires (somewhat later) and Combo2 synchs up, the
      BindingContext interprets Combo2 as having modified the record.

      Forgive me if I'm being dense, but does your solution solve this? And if
      so, could you show me an example of how to do what you are describing?

      Thanks,

      Pat
      "Ken Tucker [MVP]" wrote:
      [color=blue]
      > Hi,
      >
      > Bind the second combobox to a dataview. Use the dataview.rowfil ter
      > method to only show the right records.
      >
      > Ken
      > ---------------
      > "pmcguire" <pmcguire@discu ssions.microsof t.com> wrote in message
      > news:4C75C8A0-A0E6-4FB4-AF17-CD6732024696@mi crosoft.com...
      > I have 2 bound ComboBoxes. I want the datasource of the second to be
      > limited
      > by the selection made in the first. I can do this by responding to the
      > SelectionIndexC hanged event on the first, but this results in the
      > BindingContext' s Current.Row.Row state becoming 'Modified' whenever the
      > BindingContext position changes. What is the RIGHT way to go about this?
      >
      > Thanks,
      > --
      > Pat
      >
      >
      >[/color]

      Comment

      • Ken Tucker [MVP]

        #4
        Re: cascading combobox

        Hi,

        Dim ds As New DataSet

        Dim dv As DataView

        Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
        System.EventArg s) Handles MyBase.Load

        Dim conn As SqlConnection

        Dim strConn As String

        Dim strCmd As String

        Dim da, daProducts As SqlDataAdapter

        Dim strServer As String = "(local)"



        strConn = String.Format(" Server = {0};", strServer)

        strConn &= "Database = Northwind; Integrated Security = sspi;"

        conn = New SqlConnection(s trConn)

        da = New SqlDataAdapter( "Select * From Categories", conn)

        da.Fill(ds, "Categories ")

        daProducts = New SqlDataAdapter( "Select * from Products", conn)

        daProducts.Fill (ds, "Products")

        dv = New DataView(ds.Tab les("Products") )

        With cmbCategories

        ..DataSource = ds.Tables("Cate gories")

        ..DisplayMember = "CategoryNa me"

        ..ValueMember = "CategoryID "

        End With

        With cmbProducts

        ..DataSource = dv

        ..DisplayMember = "ProductNam e"

        End With

        End Sub

        Private Sub cmbCategories_S electedValueCha nged(ByVal sender As Object, ByVal
        e As System.EventArg s) Handles cmbCategories.S electedValueCha nged

        Try

        dv.RowFilter = "CategoryID = " & cmbCategories.S electedValue.To String

        Catch

        End Try

        End Sub



        Ken

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

        "pmcguire" <pmcguire@discu ssions.microsof t.com> wrote in message
        news:9493D707-5A72-41D6-B6EF-5204B877258A@mi crosoft.com...
        Hmm. I don't really understand.

        You mean use a filtered DataView as the second ComboBox's DataSource? I am
        already doing that. The problem isn't obtaining the list of values needed
        for the ComboBox, the problem is that I want to bind the SelectedValue of
        the
        two ComboBoxes to columns in another table. When PositionChanged fires,
        Combo1 and Combo2 both get new values; however, in general, the value Combo2
        gets from its currency manager is not yet present in its list, so after
        Combo1_Selectio nIndexChanged fires (somewhat later) and Combo2 synchs up,
        the
        BindingContext interprets Combo2 as having modified the record.

        Forgive me if I'm being dense, but does your solution solve this? And if
        so, could you show me an example of how to do what you are describing?

        Thanks,

        Pat
        "Ken Tucker [MVP]" wrote:
        [color=blue]
        > Hi,
        >
        > Bind the second combobox to a dataview. Use the
        > dataview.rowfil ter
        > method to only show the right records.
        >
        > Ken
        > ---------------
        > "pmcguire" <pmcguire@discu ssions.microsof t.com> wrote in message
        > news:4C75C8A0-A0E6-4FB4-AF17-CD6732024696@mi crosoft.com...
        > I have 2 bound ComboBoxes. I want the datasource of the second to be
        > limited
        > by the selection made in the first. I can do this by responding to the
        > SelectionIndexC hanged event on the first, but this results in the
        > BindingContext' s Current.Row.Row state becoming 'Modified' whenever the
        > BindingContext position changes. What is the RIGHT way to go about this?
        >
        > Thanks,
        > --
        > Pat
        >
        >
        >[/color]


        Comment

        • pmcguire

          #5
          Re: cascading combobox

          Hi Ken,

          Thanks for taking the time and I'm sorry it has taken me so long to respond.

          OK, I'm cool with your example as far as it goes, but let's add the final
          piece:

          Let's say you have a third table, MyTable, with 2 DataColumns, "Category"
          and "Product" and you want to do the following,

          cmbCategories.D ataBindings.Add (New Binding("Select edValue", ds,
          "MyTable.Catego ry"))
          cmbProducts.Dat aBindings.Add(N ew Binding("Select edValue", ds,
          "MyTable.Produc t"))

          mCMA=DirectCast (Me.BindingCont ext(ds,"MyTable "),CurrencyMana ger)

          How do you ensure that mCMA.Current.Ro w.RowState<>Mod ified after mCMA's
          position changes? I should point out that my particular application is now
          working, but that I have no idea why.

          Thanks again,

          Pat
          "Ken Tucker [MVP]" wrote:
          [color=blue]
          > Hi,
          >
          > Dim ds As New DataSet
          >
          > Dim dv As DataView
          >
          > Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
          > System.EventArg s) Handles MyBase.Load
          >
          > Dim conn As SqlConnection
          >
          > Dim strConn As String
          >
          > Dim strCmd As String
          >
          > Dim da, daProducts As SqlDataAdapter
          >
          > Dim strServer As String = "(local)"
          >
          >
          >
          > strConn = String.Format(" Server = {0};", strServer)
          >
          > strConn &= "Database = Northwind; Integrated Security = sspi;"
          >
          > conn = New SqlConnection(s trConn)
          >
          > da = New SqlDataAdapter( "Select * From Categories", conn)
          >
          > da.Fill(ds, "Categories ")
          >
          > daProducts = New SqlDataAdapter( "Select * from Products", conn)
          >
          > daProducts.Fill (ds, "Products")
          >
          > dv = New DataView(ds.Tab les("Products") )
          >
          > With cmbCategories
          >
          > ..DataSource = ds.Tables("Cate gories")
          >
          > ..DisplayMember = "CategoryNa me"
          >
          > ..ValueMember = "CategoryID "
          >
          > End With
          >
          > With cmbProducts
          >
          > ..DataSource = dv
          >
          > ..DisplayMember = "ProductNam e"
          >
          > End With
          >
          > End Sub
          >
          > Private Sub cmbCategories_S electedValueCha nged(ByVal sender As Object, ByVal
          > e As System.EventArg s) Handles cmbCategories.S electedValueCha nged
          >
          > Try
          >
          > dv.RowFilter = "CategoryID = " & cmbCategories.S electedValue.To String
          >
          > Catch
          >
          > End Try
          >
          > End Sub
          >
          >
          >
          > Ken
          >
          > ------------------------------
          >
          > "pmcguire" <pmcguire@discu ssions.microsof t.com> wrote in message
          > news:9493D707-5A72-41D6-B6EF-5204B877258A@mi crosoft.com...
          > Hmm. I don't really understand.
          >
          > You mean use a filtered DataView as the second ComboBox's DataSource? I am
          > already doing that. The problem isn't obtaining the list of values needed
          > for the ComboBox, the problem is that I want to bind the SelectedValue of
          > the
          > two ComboBoxes to columns in another table. When PositionChanged fires,
          > Combo1 and Combo2 both get new values; however, in general, the value Combo2
          > gets from its currency manager is not yet present in its list, so after
          > Combo1_Selectio nIndexChanged fires (somewhat later) and Combo2 synchs up,
          > the
          > BindingContext interprets Combo2 as having modified the record.
          >
          > Forgive me if I'm being dense, but does your solution solve this? And if
          > so, could you show me an example of how to do what you are describing?
          >
          > Thanks,
          >
          > Pat
          > "Ken Tucker [MVP]" wrote:
          >[color=green]
          > > Hi,
          > >
          > > Bind the second combobox to a dataview. Use the
          > > dataview.rowfil ter
          > > method to only show the right records.
          > >
          > > Ken
          > > ---------------
          > > "pmcguire" <pmcguire@discu ssions.microsof t.com> wrote in message
          > > news:4C75C8A0-A0E6-4FB4-AF17-CD6732024696@mi crosoft.com...
          > > I have 2 bound ComboBoxes. I want the datasource of the second to be
          > > limited
          > > by the selection made in the first. I can do this by responding to the
          > > SelectionIndexC hanged event on the first, but this results in the
          > > BindingContext' s Current.Row.Row state becoming 'Modified' whenever the
          > > BindingContext position changes. What is the RIGHT way to go about this?
          > >
          > > Thanks,
          > > --
          > > Pat
          > >
          > >
          > >[/color]
          >
          >
          >[/color]

          Comment

          Working...