S
Steve K.
I've created a couple of different UserControls to minimize duplicate
control and provide a consistent look for my data entry application. A
couple of examples are:
SimpleAddress
- [TextBox Controls] Address1, Address2, City, Zipcode
- [ComboBox Controls] State
InsurancePolicyDetails
- [TextBox Controls] CarrierName, PolicyNum, GroupNum, Relationship
- [MaskedTextBox Controls] CarrierPhone, CarrierFax
- [SimpleAddress Controls] CarrierAddress
You' notice that in the InsurancePolicyDetails UC there is a nested
SimpleAdress UC. This is but one example of the way I've structured my
various User Controls.
I'm struggling with how to handle the DataBinding for these User Controls.
I have the following Requirements and Concerns:
- Requirements -
1) SimpleAddress can be used in a Form or top level UserControl by iteself,
it won't always be nested in another custom UserControl and as such needs to
be bindable on it's own.
2) I need to set the State ComboBox's DataSource property (A Static IList
of states)
3) I need to bind a single entity (IE: Patient, Physician, etc) to the
SelectedValue of the SimpleAddress.State control
4) The CarrierName TextBox is a special, extended TextBox (
http://www.pmddirect.com/sklett/PMDTextBoxReview.html ) and needs to be
bound to it's DataSource via a UserControl level Bindable Property. What
I'm saying is that if I use the InsurancePolicyDetails UserControl on a form
I need to bind DIRECTLY to a property of InsurancePolicyDetails that
gets/sets the Text property of the InsuranceCarrierName TextBox.
5) Ability to DataBind to the SimpleAddress nested in the
InsurancePolicyDetails
- Problems I'm Having -
1) If I use Bindable Properties of my UserControls to expose the contained
Controls to DataBinding I could have many levels of "delegation" (I'm sure
there is a better term). For example, if I want to Bind an InsuranceCarrier
entity to the CarrierPhone control in my SimpleAddress which is contained in
my InsurancePolicyDetails Control I would need to add the following code:
<code>
// SimpleAddress.cs
[Bindable(BindableSupport.Yes)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public string Phone
{
get { return maskedTextBox_Phone.Text; }
set { maskedTextBox_Phone.Text = value; }
}
// InsurancePolicyDetails.cs
[Bindable(BindableSupport.Yes)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public string CarrierPhone
{
get { return simpleAddress1.Phone; }
set { simpleAddress1.Phone = value; }
}
</code>
Consider that I might some day want to nest InsurancePolicyDetails into a
"PatientFinancialData" UserControl and will need yet ANOTHER layer:
<code>
// PatientFinancialData.cs
[Bindable(BindableSupport.Yes)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public string PatientPrimaryCarrierPhone
{
get { return insurancePolicyDetails_Primary.CarrierPhone; }
set { insurancePolicyDetails_Primary.CarrierPhone = value; }
}
</code>
So I would flag this whole mess as "Bad Design" - shame on me! :0) But
what are my alternatives?
a) Include BindingSource objects IN the UserControls adding properties to
container Controls to expose the BindingSource.
b) Bubble the whole damn UserControl out to the world via properties and
let the concerned object (Form, UserControl, etc) setup the BindingSource to
the exposes in Controls. That needs an explanation:
<code>
// InsurancePolicyDetails.cs
public string SimpleAddress
{
get { return simpleAddress1; }
set { simpleAddress1 = value; }
}
// PatientFinancialData.cs
public string InsurancePolicyDetails
{
get { return insurancePolicyDetails_Primary; }
set { insurancePolicyDetails_Primary = value; }
}
// My Form or UserControl that is displaying these controls.cs
PatientFinancialData pfd = new PatientFinancialData();
pfd.InsurancePolicyDetails.DataSource = _patient.PrimaryPolicy;
pfd.InsurancePolicyDetails.SimpleAddress.DataSource =
_patient.PrimaryPolicy.InsuranceCarrier.Address;
// YUCK! Barf!
</code>
I don't like this either... I can't say why yet, but it doesn't seem
*correct*.
So I could go on and on. What this all boils down to is that I really don't
know the correct way to accomplish what I'm need to. I've created these
UserControls (great) and they look nice (fine) but now that it has come time
to wire them up I've got a real mess on my hands.
I'd be very curious to hear how you pros think I should design this. I
don't mean I expect you to give me a full design or anything, just some
guidance or possibly suggestion that I haven't thought of. I'd really like
to wrap up this project this weekend and this darn
UserControl/DataBinding/Properties/DataSource issue has me blocked.
Hopefully I included enough information for things to make sense.
Any feedback/help greatly appreciated!
-Steve
control and provide a consistent look for my data entry application. A
couple of examples are:
SimpleAddress
- [TextBox Controls] Address1, Address2, City, Zipcode
- [ComboBox Controls] State
InsurancePolicyDetails
- [TextBox Controls] CarrierName, PolicyNum, GroupNum, Relationship
- [MaskedTextBox Controls] CarrierPhone, CarrierFax
- [SimpleAddress Controls] CarrierAddress
You' notice that in the InsurancePolicyDetails UC there is a nested
SimpleAdress UC. This is but one example of the way I've structured my
various User Controls.
I'm struggling with how to handle the DataBinding for these User Controls.
I have the following Requirements and Concerns:
- Requirements -
1) SimpleAddress can be used in a Form or top level UserControl by iteself,
it won't always be nested in another custom UserControl and as such needs to
be bindable on it's own.
2) I need to set the State ComboBox's DataSource property (A Static IList
of states)
3) I need to bind a single entity (IE: Patient, Physician, etc) to the
SelectedValue of the SimpleAddress.State control
4) The CarrierName TextBox is a special, extended TextBox (
http://www.pmddirect.com/sklett/PMDTextBoxReview.html ) and needs to be
bound to it's DataSource via a UserControl level Bindable Property. What
I'm saying is that if I use the InsurancePolicyDetails UserControl on a form
I need to bind DIRECTLY to a property of InsurancePolicyDetails that
gets/sets the Text property of the InsuranceCarrierName TextBox.
5) Ability to DataBind to the SimpleAddress nested in the
InsurancePolicyDetails
- Problems I'm Having -
1) If I use Bindable Properties of my UserControls to expose the contained
Controls to DataBinding I could have many levels of "delegation" (I'm sure
there is a better term). For example, if I want to Bind an InsuranceCarrier
entity to the CarrierPhone control in my SimpleAddress which is contained in
my InsurancePolicyDetails Control I would need to add the following code:
<code>
// SimpleAddress.cs
[Bindable(BindableSupport.Yes)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public string Phone
{
get { return maskedTextBox_Phone.Text; }
set { maskedTextBox_Phone.Text = value; }
}
// InsurancePolicyDetails.cs
[Bindable(BindableSupport.Yes)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public string CarrierPhone
{
get { return simpleAddress1.Phone; }
set { simpleAddress1.Phone = value; }
}
</code>
Consider that I might some day want to nest InsurancePolicyDetails into a
"PatientFinancialData" UserControl and will need yet ANOTHER layer:
<code>
// PatientFinancialData.cs
[Bindable(BindableSupport.Yes)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public string PatientPrimaryCarrierPhone
{
get { return insurancePolicyDetails_Primary.CarrierPhone; }
set { insurancePolicyDetails_Primary.CarrierPhone = value; }
}
</code>
So I would flag this whole mess as "Bad Design" - shame on me! :0) But
what are my alternatives?
a) Include BindingSource objects IN the UserControls adding properties to
container Controls to expose the BindingSource.
b) Bubble the whole damn UserControl out to the world via properties and
let the concerned object (Form, UserControl, etc) setup the BindingSource to
the exposes in Controls. That needs an explanation:
<code>
// InsurancePolicyDetails.cs
public string SimpleAddress
{
get { return simpleAddress1; }
set { simpleAddress1 = value; }
}
// PatientFinancialData.cs
public string InsurancePolicyDetails
{
get { return insurancePolicyDetails_Primary; }
set { insurancePolicyDetails_Primary = value; }
}
// My Form or UserControl that is displaying these controls.cs
PatientFinancialData pfd = new PatientFinancialData();
pfd.InsurancePolicyDetails.DataSource = _patient.PrimaryPolicy;
pfd.InsurancePolicyDetails.SimpleAddress.DataSource =
_patient.PrimaryPolicy.InsuranceCarrier.Address;
// YUCK! Barf!
</code>
I don't like this either... I can't say why yet, but it doesn't seem
*correct*.
So I could go on and on. What this all boils down to is that I really don't
know the correct way to accomplish what I'm need to. I've created these
UserControls (great) and they look nice (fine) but now that it has come time
to wire them up I've got a real mess on my hands.
I'd be very curious to hear how you pros think I should design this. I
don't mean I expect you to give me a full design or anything, just some
guidance or possibly suggestion that I haven't thought of. I'd really like
to wrap up this project this weekend and this darn
UserControl/DataBinding/Properties/DataSource issue has me blocked.
Hopefully I included enough information for things to make sense.
Any feedback/help greatly appreciated!
-Steve