473,386 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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
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,
--
Pat
Nov 21 '05 #1
4 7806
Hi,

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

Ken
---------------
"pmcguire" <pm******@discussions.microsoft.com> wrote in message
news:4C**********************************@microsof t.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
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,
--
Pat
Nov 21 '05 #2
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
"Ken Tucker [MVP]" wrote:
Hi,

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

Ken
---------------
"pmcguire" <pm******@discussions.microsoft.com> wrote in message
news:4C**********************************@microsof t.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
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,
--
Pat

Nov 21 '05 #3
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

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

"pmcguire" <pm******@discussions.microsoft.com> wrote in message
news:94**********************************@microsof t.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_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
"Ken Tucker [MVP]" wrote:
Hi,

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

Ken
---------------
"pmcguire" <pm******@discussions.microsoft.com> wrote in message
news:4C**********************************@microsof t.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
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,
--
Pat

Nov 21 '05 #4
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"),Cu rrencyManager)

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
"Ken Tucker [MVP]" wrote:
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

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

"pmcguire" <pm******@discussions.microsoft.com> wrote in message
news:94**********************************@microsof t.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_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
"Ken Tucker [MVP]" wrote:
Hi,

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

Ken
---------------
"pmcguire" <pm******@discussions.microsoft.com> wrote in message
news:4C**********************************@microsof t.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
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,
--
Pat


Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Humpty Dumpty | last post by:
Hi folks, here's a challenge: I have a dynamically created cascading menu in Tkinter that can be quite large because it is created from a file. I tried using lazy creation so only the menu item...
1
by: JMosey | last post by:
Not sure if this has been covered ( a google search came up pretty bare). I have a site that: - has multi-level cascading menus - floats center of the browser window - Will have fairly heavy...
9
by: Edwinah63 | last post by:
Hi everyone, Please let there be someone out there who can help. I have two BOUND combo boxes on a continuous form, the second being dependent on the first. I have no problem getting the...
6
by: visionstate | last post by:
Hi there, I am building a database that requires cascading lists on a form. I currently have (I may be adding more later) 3 combo boxes on my form - Department, Surname and Forename. The user...
1
by: wizardRahl | last post by:
Hello all, I am fairly new to Access. I have a decent understanding of database concepts from working with sql developer and Oracle's APEX. In MS access, I would like to know how to populate a...
3
by: tcveltma | last post by:
Hi Everyone, I have a cascading combo box, where you choose a general topic, and the next combo box only shows the related options....easy. Now I'm being told that one of the options I have can...
19
by: Amanduh | last post by:
Hi again, brilliant developers. I'm having serious issues with cascading comboboxes. I had it working perfectly before, but then was asked to add an additional variable and everything went haywire...
4
klarae99
by: klarae99 | last post by:
Hello, I am working on an Access 2003 Database. The tables that pertain to this issue are tblOrg, tblState, tblCity, and tblZip. I have posted the table structure with only the pertinant fields...
6
Walt in Decatur
by: Walt in Decatur | last post by:
I have implemented successfully a single-cascade ComboBox combination on a form in my database (using an AfterUpdate event code). I have also successfully implemented a ComboBox + TextBox...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.