Link to home
Start Free TrialLog in
Avatar of softwarea
softwarea

asked on

Newbie: Simple Databinding in WinForms

Hi experts,

I have a small WinForms application that contains
- a DataGridView,
- a BindingNavigator,
- a BindingSource and
- a Textbox

The DataGridView shows commodities coming from a database and the BindingNavigator helps the user scrolling through the rows of commodities. DataGridView and BindingNavigator are connected to the same BindingSource. Everything works as expected.

However: I want the TextBox to show a certain value (i.e. the commodity's name) of the currently focused row in the DataGridView.

Thus I set a databinding in the Forms Load()-event like this:
            TextBox.DataBindings.Add("Text", commodityDataSource, "CommodityName");

When I start the application, the TextBox shows data from the first DataGridView row as expected.

But here is my problem: When I select another row in the DataGridView via Mouse or via Navigator the content of the TextBox is NOT updated.

What am I missing? Thanks for any help!
Ingmar
Avatar of traxion
traxion

You'll have to capture the event of hte selected row.
I believe you can trap it with the "RowEnter" event, then grab the CommodityName for the current row and populate the text box.
ASKER CERTIFIED SOLUTION
Avatar of traxion
traxion

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of softwarea

ASKER

Sorry, sorry, sorry! Thank you for your answer traxion, but I could not answer earlier.
Ok, so I really have to take care of data scrolling manually.
I thought/hoped that the databinding mechanism would do that automatically.
So, thank you again!