Question Using One Toolbar or BindingNavigator for all BindingSources?

adshocker

Well-known member
Joined
Jun 30, 2007
Messages
180
Programming Experience
Beginner
Hi all,

Normally in a form, it is possible to have more than one bindingsource.

How does one tell the Toolbar or BindingNavigator which BindingSource to use, depending on which the cursor is focused?

Thanks.
 
hi,

thanks for the reply.

i am aware of the BindingSource property of the BindingNavigator. the problem i'm having is that a BindingNavigator can only have one BindingSource... what if a form has a master and detail tables in it. for ex... Employees table (Master) and Employee_Assignments table (Detail). Employees table has Employees_BindingSource and Employees_Assignments has Employees_AssignmentsBindingSource. Initially, the BindingNavigator has Employees_BindingSource for its BindingSource. so when clicking the AddNew button, it adds a record for the Employees datatable. what if you wanted to add a record for the Employees_Assignments Datatable, how should this be done properly?

thanks
 
what if you wanted to add a record for the Employees_Assignments Datatable, how should this be done properly?

thanks

By having 2 binding navigators and designing the UI properly so that it is obvious what does what. e.g. If the form is showing 2 independent BS and BN, it should probably have 2 groupboxes,titled suitably, and the relevant BNs docked to the bottom of the boxes

If the form is showing master/detail then perhaps it should have one BN docked to the bottom of the window and the other BN docked to the bottom of a group box titled suitably for the child. The parent BN should be visibly bigger and perhaps contain text items that set it apart from the child. Consider not having one of the BNs at all
 
By having 2 binding navigators and designing the UI properly so that it is obvious what does what. e.g. If the form is showing 2 independent BS and BN, it should probably have 2 groupboxes,titled suitably, and the relevant BNs docked to the bottom of the boxes

If the form is showing master/detail then perhaps it should have one BN docked to the bottom of the window and the other BN docked to the bottom of a group box titled suitably for the child. The parent BN should be visibly bigger and perhaps contain text items that set it apart from the child. Consider not having one of the BNs at all

i see.

i've been exposed to only one IDE before that uses only 1 Toolbar for all Tables (Oracle Forms).. and this toolbar automatically adjusts to whatever table the current cursor is on.. if the cursor is in one of the items in the master table, click the Add button adds a record to the master table.. and vice versa.. if the cursor is in one of the items in the Child table, then clicking the Add button adds a record to the child table.

all this while i was looking for a way to do this in .Net.. and it was a little bit tough to do. :D

then again, the clients will be the one to decide in the end.

thanks.
 
If you want a single BindingNavigator with multiple BindingSources then you simply have to change the BindingNavigator's BindingSource property each time focus moves to a different control. How do you know that a control has received focus? It raises its Enter event. You can simply handle the Enter event for all your bound controls and get the bound BindingSource. You may only need one method to handle all those events or you may need multiple methods, depending on what different types of bound controls you have. For instance, all controls where you've bound the Text property could be handled together:
VB.NET:
Expand Collapse Copy
Dim ds As Object = DirectCast(sender, Control).DataBindings("Text").DataSource

myBindingNavigator.BindingSource = DirectCast(ds, BindingSource)
You could group all ComboBoxes and ListBoxes together as they are all ListControls. You could also group all DataGridViews together. Although, in the case of ListControls and DataGridViews, you would be getting the DataSource property each time, it;s actually a different property so they would need to be handled separately.
 
thanks... much appreciated.

by grouping datagridviews, listcontrols did you mean something like this?

VB.NET:
Expand Collapse Copy
        Dim ds As Object
        If TypeOf DirectCast(sender, Control) Is ListControl Then
            ds = DirectCast(sender, ListControl).DataSource
        ElseIf TypeOf DirectCast(sender, Control) Is DataGridView Then
            ds = DirectCast(sender, DataGridView).DataSource
        ElseIf TypeOf DirectCast(sender, Control) Is TextBox Then
            ds = DirectCast(sender, TextBox).DataBindings.Item("Text").DataSource
        ElseIf TypeOf DirectCast(sender, Control) Is CheckBox Then
            ds = DirectCast(sender, TextBox).DataBindings.Item("Checked").DataSource
        End If

  BindingNavigator1.BindingSource = DirectCast(ds, BindingSource)
 
I actually meant using a separate method for each group of control types but you could do it like that if you wanted. Just note that there's no point casting the sender as type Control before determining its type. If the sender is a ListControl then it's a ListControl, whether you fist cast it as type Control or not.
 
i see.

i've been exposed to only one IDE before that uses only 1 Toolbar for all Tables (Oracle Forms).. and this toolbar automatically adjusts to whatever table the current cursor is on.. if the cursor is in one of the items in the master table, click the Add button adds a record to the master table.. and vice versa.. if the cursor is in one of the items in the Child table, then clicking the Add button adds a record to the child table.

all this while i was looking for a way to do this in .Net.. and it was a little bit tough to do. :D

then again, the clients will be the one to decide in the end.

thanks.

Things like this are usually a dumb thing to do from an HCI point of view, because the user will develop knowledge that certain buttons are available, and then one day they look for them and they don't exist (because the cursor is in a different box) and the screen realestate is reused for something else. Can you imagine how confusing it would be if Microsoft Word hid the Save button if there was nothing to save? As it is it leaves it there, where you know to find it, but disables it to let you know it is not an applicable action. I've never used the Office 2007 ribbon, but apparently it takes a lot of getting used to because it changes a lot based on the context of what the user is doing; people really didn't/don't like it because they like everything to be in a place they know.

If you let the clients drive every decision, you'll go nuts. You have to step in as the voice of reason on a lot of things. Try finding a builder who will build you an upside-down house; the first question I'd ask someone is "Why do you want the pointy bit at the bottom and the flat bit at the top? It'll collect rain, and if you put a grand piano near an outside wall, your house will fall over."
If you let clients decide what they want when they havent got a clue about what they want, you'll end up with a system that's crap and reflects badly on you as a developer.
 
If you let the clients drive every decision, you'll go nuts. You have to step in as the voice of reason on a lot of things. Try finding a builder who will build you an upside-down house; the first question I'd ask someone is "Why do you want the pointy bit at the bottom and the flat bit at the top? It'll collect rain, and if you put a grand piano near an outside wall, your house will fall over."
If you let clients decide what they want when they havent got a clue about what they want, you'll end up with a system that's crap and reflects badly on you as a developer.

i'll keep that in mind..

what i normally do is give options and then let them decide on which to take. although sometimes they ask for more options or give suggestions.. if it's highly unreasonable or impractical i give explanations or situations why its not a good idea.

thanks.
 
Back
Top