Databinding Question

jswota

Well-known member
Joined
Feb 23, 2009
Messages
49
Programming Experience
Beginner
Hi,

I have a grid and several textbox controls bound to the same bindingsource. When i click a row in the grid the texbox controls show the corresponding data values. This makes sense. But what i want to do is allow my users to "open" a grid item by double clicking a grid row. I don't want the textbox controls to display anything until after a user "opens" a grid item by double clicking the row. Do i have to bind my textbox controls at runtime or is there a more direct way to do this (i.e. disabling and enabling databinding)?

Thanks,
Joel
 
After thinking about it all i am really looking for is this - Is there any way to have the grid only change the bindingsource position when a row is double clicked?
 
That doesn't really seem to make sense. I would think that double-clicking would be appropriate if you were going to open a separate dialogue to display the record but not if you're displaying it in the same form. How you design your UI is obviously up to you but that seems counter-intuitive to me.

To answer your question as asked, no it's not possible to stop the BindingSource updating its Position when the user clicks a row in the grid. That may not be an issue though. I haven't tested this but I would think that you could just use two BindingSources: one for the grid and one for the TextBoxes. The Position of the one bound to the grid will change as the user clicks on a row or uses the keyboard to navigate but that won't affect the one bound to the TextBoxes. You can handle the CellDoubleClick event of the grid and simply assign the Position of one to the Position of the other.
 
OK. Thanks. I am currently using two bindingsources like you suggested. It does work ok. It just takes a bit more work when saving changes to keep the two sources sync'd.

My app is a tabbed interface. Each tab has several docking windows. In this situation i am displaying items in one docking window and i don't want the other docking windows to be enabled and populated until an item is double clicked ("opened"). The only reason that the texteditors are giving me trouble is because they are bound to the same bindingsource that the main grid is. All of the other docking windows have grids that are bound to different sources that are loaded when a row is double clicked. So they remain empty until i say so. But as soon as i populate the main grid, the texteditors display the corresponding row values even when they are disabled ("greyed"). I don't want to hide them just because. I could, but i prefer they be visible. Also, the values change whenever the user select another row. The desired functionality is to double click the row to open an item.

Everything works fine right now but i feel like i am no longer taking full advantage of ADO. I don't want to end up in left field.

Thanks,
Joel
 

Attachments

  • main.jpg
    main.jpg
    158 KB · Views: 33
OK. Thanks. I am currently using two bindingsources like you suggested. It does work ok. It just takes a bit more work when saving changes to keep the two sources sync'd.

No it doesn't. You'd still only use one DataTable and bind it to both BindingSources.
 
Hey, Thanks again for the help.

It's a bit more complicated. Tough to explain the entire situation. The main grid needs to allow users to create new rows that are immediately saved to the database. The user can then click the newly created (or any other) row to open the item. He can make changes to the item and will be prompted to "Save Changes" when he is finished. So for some time the data in the main grid might differ from the data displayed in the texteditors. So when the item is saved and the changes are written back to the database, the main grid needs to be updated to reflect the new changes.

Here's a similar situation: Let's say you have a Projects screen with a grid listing all of the projects. You double click a grid row and the project opens in a new Project Info form. You then make a change to the - let's say - Description field and save. When you go back to the Projects screen you need to see the new description in the grid.

This is pretty much what i am doing except everything is visible at the same time in the various docking windows. So you won't actually see the grid info update until the changes in the texteditors are saved.

I am ok with the way it works now but was just wondering if i am overlooking something. I was wondering if i could change the way the grid affects the bindingsource position. If i could make it move position only if the user double clicks a row instead of single clicking. I don't think i can.

Thanks a lot for your help and patience,
Joel
 
Back
Top