No DDX equiv. in .NET framework?!

  • Thread starter Thread starter Julie
  • Start date Start date
J

Julie

Seems short-sighted to me to not include an equivalent to the MFC DDX stuff
where you can w/ (the wizard or by hand) create a mapping between a variable
and its UI representation (e.g. CString w/ a TextBox edit control).

I'm finding it very tedious (and error prone) to have to do this association by
hand through events.

In my opinion, it seems like it would have been beneficial to add some type of
associative functionality at the language level, or at the very least, at the
framework level.
 
Julie said:
Seems short-sighted to me to not include an equivalent to the MFC DDX stuff
where you can w/ (the wizard or by hand) create a mapping between a variable
and its UI representation (e.g. CString w/ a TextBox edit control).

I'm finding it very tedious (and error prone) to have to do this association by
hand through events.

In my opinion, it seems like it would have been beneficial to add some type of
associative functionality at the language level, or at the very least, at the
framework level.

Julie,

What's wrong with using databinding?

Erik
 
Erik said:
Julie,

What's wrong with using databinding?

Erik

I looked into databinding, but it looks to me like a (primarily ASP.NET) way to
bind controls to a data source. I didn't see anything that was suitable for
simple control-variable binding...

Did I miss something? If so, any links or references?
 
I looked into databinding, but it looks to me like a (primarily ASP.NET)
way to
bind controls to a data source. I didn't see anything that was suitable for
simple control-variable binding...

Did I miss something? If so, any links or references?

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
 
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.
 
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.

I don't think the simplicity exists in the manner you describe. However,
the article I referenced had nothing to do with databases or database
objects. A simple class (or struct, I bet) will do. Look at this class:

Class Customer
{
public int CustomerID
{
get { // do whatever}
set { // do whatever}
}
}

An array of that Customer class is all you need for databinding.

textBoxID.DataBindings.Add("Text", custList, "CustomerID")

It's telling the textBox to bind to the CustomerID field of the Customer
classes enumerated in custList. When you call EndEdit (very much like your
DDX_Text method), it updates from the "Text" property of textBoxID to the
"CustomerID" property of your Customer object.

It's not direct assignment to a string like MFC, but it's really not all
that big of a step up.

Erik
 
Erik said:
I don't think the simplicity exists in the manner you describe. However,
the article I referenced had nothing to do with databases or database
objects. A simple class (or struct, I bet) will do. Look at this class:

Class Customer
{
public int CustomerID
{
get { // do whatever}
set { // do whatever}
}
}

An array of that Customer class is all you need for databinding.

textBoxID.DataBindings.Add("Text", custList, "CustomerID")

It's telling the textBox to bind to the CustomerID field of the Customer
classes enumerated in custList. When you call EndEdit (very much like your
DDX_Text method), it updates from the "Text" property of textBoxID to the
"CustomerID" property of your Customer object.

It's not direct assignment to a string like MFC, but it's really not all
that big of a step up.

Erik

Yes, I did see what you were talking about as well. Even though the
databinding isn't a big step it, it is a step, and multiplied a 100 times or
so, it can quickly add up to a maintenance problem and the source of bugs due
to hand-entering. That is what I'm hoping to avoid.

Regardless, thanks for the links and additional information. I haven't spent
much time studying databinding up to now, but will put it on my list of things
to experiment with.
 
Julie,
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.
You can use "Data Binding" to associate a Property with a UI counterpart,
note that ASP.NET data binding works a little different then Windows Forms
data binding.

Based on you using DDX & Dialog, I will presume you want a Windows Forms
example.
string searchString; // variable containing search string value. This persists

TextBox searchStringUI; // control that displays the current value of the

searchStringUI.DataBindings.Add(new Binding
("Text", this, "SearchString"));

Where SearchString is the property that exposes the searchString variable.

I would probably bind to an object rather then "this", such as a
SeachOptions object that has a SeachString property. The dialog itself would
have a reference to the SeachOptions object.

Hope this helps
Jay
 
Jay B. Harlow said:
Julie,
You can use "Data Binding" to associate a Property with a UI counterpart,
note that ASP.NET data binding works a little different then Windows Forms
data binding.

Based on you using DDX & Dialog, I will presume you want a Windows Forms
example.


searchStringUI.DataBindings.Add(new Binding
("Text", this, "SearchString"));

Where SearchString is the property that exposes the searchString variable.

I would probably bind to an object rather then "this", such as a
SeachOptions object that has a SeachString property. The dialog itself would
have a reference to the SeachOptions object.

Hope this helps
Jay

Actually, this is working out perfectly. Thanks for the direction and your
persistence.

I've got to tell you though, I have found the online documentation for
DataBinding to be horrible. Very hard to follow, and not clear at all... Just
marginally better than the C++ STL 'documentation'...

I tried figuring out (if possible) how to do databindings from the control
DataBindings properties. I could never get anything to show up in any of the
lists, so I just resorted to creating the data bindings by hand in the
Initialize method.

Thanks again.
 
Julie,
Do you have it working (binding to properties on any object)?

Jay
 
Back
Top