DataBinding to current row

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

Peter Morris [Droopy eyes software]

I have a grid with 2 columns

string Name
Decimal NewPrice

I have a TextBox at the bottom of the form, I am manually getting/setting
the NewPrice of the current row whenever the row changes or the TextBox
loses focus.

Is there a more automated way of doing this? I've written the same code for
about 5 different forms now and it is becoming monotonous :-)

Thanks

Pete
 
Yes, just bind the text box to data source.

As long as list control is bound to the same data source, currency manager
will change rows automatically.


--
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).
 
Hi Ilya

How do I specify MyDataGrid1 as the currency manager to use for the textbox?

Form1
MyDataGrid1
MyTextBox1

How do I databind MyTextBox1 to MyDataGrid1.DataSource.FirstName and have
WinForms know that MyDataGrid1 specifies the current row?

Thanks

Pete
 
CurrencyManager is in fact a class in data binding engine which takes care
of that, it's not your DataGrid.



You don't need to do anything besides setting up binding, all will be
handled automatically.

In this case here's what you need to do:



MyDataGrid1.DataSource = dataTable
MyTextBox1.DataBindings.Add ("Text", dataTable, "FirstName")


--
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).
 
MyDataGrid1.DataSource = dataTable
MyTextBox1.DataBindings.Add ("Text", dataTable, "FirstName")

Aha! That's why I was suspicious that this wouldn't work, I had already
tried it and it didn't. However I was using SmartGrid from Resco, after you
suggested it should work I tried it with a standard DataGrid and it worked
just fine. I shall write to Resco and tell them they have a bug.

In the meantime is there a way I can implement this myself without modifying
the grid source, or is it too complicated?


Thanks

Pete
 
You should be able to move rows manually by setting Position property on
CurrencyManager.

I'm sure SmartGrid has some sort of "CurrentRowChanged" event, so you can
update Position in it's handler.



Please see this for a code sample:

http://msdn.microsoft.com/library/d...stemwindowsformscurrencymanagerclasstopic.asp

--
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).
 
Back
Top