Erik said:
Julie,
Databinding is very useful in windows forms as well as ASP.NET. If I
remember the MFC thing you mentioned (it's been a while), you had to call
something like bind(false) or bind(true) to make the app copy from control
values to data structure, or back again. The same goes for .NET
databinding, except they call it BeginEdit and EndEdit.
The nice thing about databinding is that you don't have to use bloated
ADO.NET datasets at all - all your data structures have to do to take
advantage of data binding is implement IList. So an array of your business
objects, or a strongly typed collection will work just fine.
http://msdn.microsoft.com/library/d.../html/vbconinterfacesrelatedtodatabinding.asp
And here's a few code snippets that show simple binding (the kind you are
trying to do):
http://samples.gotdotnet.com/quickstart/winforms/doc/WinFormsData.aspx#SimpleDatabinding
Admittedly, it's not as simple as the MFC version.
Erik
I think that we are talking about different manifestations of the DDX
mechanism. I have no need for db binding, just simple associations between a
variable and its UI counterpart in a dialog.
For example:
string searchString; // variable containing search string value. This persists
before and after the UI is created, therefore it must be maintained separately
from the UI
TextBox searchStringUI; // control that displays the current value of the
search string, as well as processes (and stores) any changes to the search
string to the underlying varialble (searchString) in this case
To 'connect' these to elements, I have to resort to the following by hand:
// In form initialization:
searchStringUI.Text = searchString
// Add an searchStringUI.OnChanged event handler
void searchStringUI_OnTextChanged()
{
searchString = searchStringUI.Text;
}
This is all no biggie for one or two variables and controls, but when I'm
dealing w/ 10's of variables in multiple dialogs, it quickly adds up and
becomes a very error prone process as well.
For MFC, the process was trivial: open the ClassWizard for that form (dialog),
and add a member variable for that particular control. The wizard would then
add something like the following line of code to your source:
DDX_Text(searchString, searchStringUI) // simplified for the purposes of this
discussion
which was a bi-directional excange of the variable value and the UI control,
depending on the 'direction' (update control value or retrieve from control).
No such simplicity exists in C#/.NET? Like I said, it seems that there would
be value at the language level, or at the minimum, at the framework level.