DataBind to current row of a datagrid

  • Thread starter Peter Morris [Droopy eyes software]
  • Start date
P

Peter Morris [Droopy eyes software]

Hi all

As DataGrid is readonly I decided to add an UpDown control to the bottom of
my form in order to allow the user to edit a numerical value of the selected
row.

I have done this in code, but I suspect that there must be a way to do this
via databinding. So my question is this, how can I databind the Value
property of my UpDown control to the CurrentRow.RecordedAmount, but when the
selected row changes the UpDown will be editing the newly selected row
instead?

Thanks

Pete
 
G

Ginny Caughey [MVP]

Peter,

I don't know of a way to do this automatically using data binding. Since you
have a coded solution already, I'd just go with that. It will give you more
control than an "automatic" one would if it were available anyway.
 
I

Ilya Tumanov [MS]

In fact this scenario is automatically handled by CurrencyManager class in
data binding engine.

If you have DataTable bound to the grid and bunch of simple controls bound
to the same DataTable, CurrencyManager would bind simple controls to the
current row in the grid.



So, there's nothing to code besides setting up bindings like this:



dataGrid.DataSource = dataTable;

upDown.Bindings.Add("Value", dataTable, "RecordedAmount");



Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

*** Want to find answers instantly? Here's how... ***

1. Go to
http://groups-beta.google.com/group/microsoft.public.dotnet.framework.compactframework?hl=en
2. Type your question in the text box near "Search this group" button.
3. Hit "Search this group" button.
4. Read answer(s).
 
G

Ginny Caughey [MVP]

Thanks, Ilya. I misread what he wanted to do and thought he wanted to change
the selected row in the grid based on the up/down control. But in any case,
as long as he has a working solution...
 
P

Peter Morris [Droopy eyes software]

Ah, I can databind to the datagrid then? I will try that, thanks!
 

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

Top