473,382 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Data binding with enums?

I want to data bind a user control and a business object, using a
BindingSource control. The control has a 'Priority' property that takes a
'Priority' enum (High, Normal, Low). The business object has a property with
the same name, which takes an identical enum.

Data binding isn't working, and I think it's because the two enums are
different. Even though they have the same name and the same elements, they
are declared under different namespaces.

Why two enums? It lets the control and the business object be developed
independently of each other, and it reduces the coupling between them. But
apparently, it's killing the data binding between the control property and
the object property. The ability of a data binding to perform implicit
conversions does not extend this far.

Has anyone else run into a problem like this? Any suggestions? I'd like to
be able to perform a cast or a conversion as the data moves between the
control and the object, but I don't see any way to do that. Thanks in
advance.

--
David Veeneman
Foresight Systems
Mar 2 '06 #1
2 4774
I found my answer--you simply hook into the Format and Parse events fired by
the data binding for the control property in question:

userControl1.DataBindings["Priority"].Format += new
ConvertEventHandler(EditPanelProjects_Format);
userControl1.DataBindings["Priority"].Parse += new
ConvertEventHandler(EditPanelProjects_Parse);

The event handler will take an argument of type ConvertEventArgs.

When the Format event fires, ConvertEventArgs.Value contains the raw value
from the business object. Convert it to whatever type the control needs and
set ConvertEventArgs.Value to the converted value.

When the Parse event fires, ConvertEventArgs.Value contains the formatted
value from the control. Convert it to whatever type the business object
needs and set ConvertEventArgs.Value to the converted value.

The events are designed to facilitate formatting a data value for display in
a control, and parsing a formatted value from a control for storage in a
data source. But they can be used for any type of conversion, such as the
one I need.

--
David Veeneman
Foresight Systems
Mar 2 '06 #2
Think what would happen if you changed the enums to be incompatible!
It would break your databinding however you do it.
If they can't be incompatible then they aren't independent.
Use a single enum in a separate assembly that both of your other assemblies
reference.

P.S. If you ever intend your app to be used by non english speakers then the
whole enum approach will not work because it can't be internationalized.

"David Veeneman" <da****@nospam.com> wrote in message
news:eZ**************@TK2MSFTNGP09.phx.gbl...
I want to data bind a user control and a business object, using a
BindingSource control. The control has a 'Priority' property that takes a
'Priority' enum (High, Normal, Low). The business object has a property
with the same name, which takes an identical enum.

Data binding isn't working, and I think it's because the two enums are
different. Even though they have the same name and the same elements, they
are declared under different namespaces.

Why two enums? It lets the control and the business object be developed
independently of each other, and it reduces the coupling between them.
But apparently, it's killing the data binding between the control property
and the object property. The ability of a data binding to perform implicit
conversions does not extend this far.

Has anyone else run into a problem like this? Any suggestions? I'd like to
be able to perform a cast or a conversion as the data moves between the
control and the object, but I don't see any way to do that. Thanks in
advance.

--
David Veeneman
Foresight Systems

Mar 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: SpaceCowboy | last post by:
I recently got into a discussion with a co-worker about using enums across a dll interface. He wanted to use chars instead, argueing that depending on compiler settings the size of an enum could...
0
by: Ann Morris | last post by:
INTRODUCTION One of the most powerful aspects of .NET and Windows Forms is data binding. Data binding is the process of associating user interface (UI) elements with a data source to generate a...
16
by: D Witherspoon | last post by:
I am developing a Windows Forms application in VB.NET that will use .NET remoting to access the data tier classes. A very simple way I have come up with is by creating typed (.xsd) datasets. For...
1
by: | last post by:
Hi, Is there any good links for datatype interop? I need to pass some structure pointers into an unmanaged method and return char* etc but having some problems in my C++/CLI proxy class. I...
0
by: NicK chlam via DotNetMonster.com | last post by:
this is the error i get System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.Common.DbDataAdapter.Update(DataRow dataRows, DataTableMapping tableMapping) at...
0
by: mjsterz | last post by:
I've been working with VB .NET for less than a year and this is the first time I've posted on one of these groups, so let me apologize beforehand if I'm being unclear, not posting my issue...
14
by: Rolf Welskes | last post by:
Hello, I have an ObjectDataSource which has as business-object a simple array of strings. No problem. I have an own (custom) control to which I give the DataSourceId and in the custom-control...
9
by: Anil Gupte | last post by:
After reading a tutorial and fiddling, I finally got this to work. I can now put two tables created with a DataTable class into a DataRelation. Phew! And it works! Dim tblSliceInfo As New...
5
by: guy.gorodish | last post by:
hi, i have a c# interop that pass struct into c dll. for some reason the data transfered into the c function is with incorrect order (meaning - members of the struct get other struct values and...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.