cascading combobox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
SelectionIndexChanged event on the first, but this results in the
BindingContext's Current.Row.Rowstate becoming 'Modified' whenever the
BindingContext position changes. What is the RIGHT way to go about this?

Thanks,
 
Hi,

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

Ken
---------------
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
SelectionIndexChanged event on the first, but this results in the
BindingContext's Current.Row.Rowstate becoming 'Modified' whenever the
BindingContext position changes. What is the RIGHT way to go about this?

Thanks,
 
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_SelectionIndexChanged 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
 
Hi,

Dim ds As New DataSet

Dim dv As DataView

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) 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(strConn)

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.Tables("Products"))

With cmbCategories

..DataSource = ds.Tables("Categories")

..DisplayMember = "CategoryName"

..ValueMember = "CategoryID"

End With

With cmbProducts

..DataSource = dv

..DisplayMember = "ProductName"

End With

End Sub

Private Sub cmbCategories_SelectedValueChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles cmbCategories.SelectedValueChanged

Try

dv.RowFilter = "CategoryID = " & cmbCategories.SelectedValue.ToString

Catch

End Try

End Sub



Ken

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

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_SelectionIndexChanged 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
 
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.DataBindings.Add(New Binding("SelectedValue", ds,
"MyTable.Category"))
cmbProducts.DataBindings.Add(New Binding("SelectedValue", ds,
"MyTable.Product"))

mCMA=DirectCast(Me.BindingContext(ds,"MyTable"),CurrencyManager)

How do you ensure that mCMA.Current.Row.RowState<>Modified 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top