I'm having trouble when binding a control to a date property in a
Class. I have a grid bound to a list class. When I add Items to the
list everything works fine. But when I edit and existing object in the
list I can only change one of the bound control items. Here is the
form code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace ACS.UI
{
/// <summary>
/// This form will allow the user to add a new mistreatment.
/// </summary>
public class MistreatmentForm : ACSBaseSecondaryForm
{
private App.Case.Arrest.MistreatmentList mMistreatmentList;
private App.Case.Arrest.Mistreatment mMistreatment;
private ACS.UI.Controls.Label lblMisDate;
private ACS.UI.Controls.CheckBox chkConfirmed;
private ACS.UI.Controls.CheckBox chkProtest;
private ACS.UI.Controls.TextBox txtDescript;
private ACS.UI.Controls.TextBox txtAction;
private ACS.UI.Controls.Label lblAction;
private ACS.UI.Controls.Label lblProtest;
private ACS.UI.Controls.TextBox txtProtest;
private ACS.UI.Controls.TextBox txtResolution;
private ACS.UI.Controls.Label lblResolution;
private ACS.UI.Controls.DateTimePicker dtpMistreatmentDate;
private ACS.UI.Controls.Label lblDescription;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
/// <summary>
/// This constructor is here for design time support. If used at
run time it
/// will throw an exception.
/// </summary>
public MistreatmentForm()
{
if (this.DesignMode == false)
{
throw new Exception("The form cannot be instatiated without an
object");
}
else
{
InitializeComponent();
}
}
/// <summary>
/// This is the main constructor for the form. All setup should be
performed here.
/// </summary>
/// <param name="oMistreatment">The mistreatment being edited or
reviewed.</param>
public MistreatmentForm(ACS.App.Case.Arrest.ArrestService oArrest)
{
mMistreatmentList = oArrest.MistreatmentList;
mMistreatment = new App.Case.Arrest.Mistreatment(oArrest);
InitializeComponent();
}
public MistreatmentForm(ACS.App.Case.Arrest.Mistreatment
oMistreatment)
{
mMistreatment = oMistreatment;
InitializeComponent();
}
private void BindMistreatment()
{
//Bind the objects to form controls
dtpMistreatmentDate.DataBindings.Add(new
System.Windows.Forms.Binding("Text", mMistreatment, "Date"));
chkConfirmed.DataBindings.Add(new
System.Windows.Forms.Binding("Checked", mMistreatment, "Confirmed"));
chkProtest.DataBindings.Add(new
System.Windows.Forms.Binding("Checked", mMistreatment,
"ProtestFiled"));
txtDescript.DataBindings.Add(new
System.Windows.Forms.Binding("Text", mMistreatment, "Description"));
txtAction.DataBindings.Add(new System.Windows.Forms.Binding("Text",
mMistreatment, "ActionTaken"));
txtProtest.DataBindings.Add(new
System.Windows.Forms.Binding("Text", mMistreatment, "HowProtested"));
txtResolution.DataBindings.Add(new
System.Windows.Forms.Binding("Text", mMistreatment, "Resolution"));
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.lblMisDate = new ACS.UI.Controls.Label();
this.dtpMistreatmentDate = new ACS.UI.Controls.DateTimePicker();
this.chkConfirmed = new ACS.UI.Controls.CheckBox();
this.chkProtest = new ACS.UI.Controls.CheckBox();
this.txtDescript = new ACS.UI.Controls.TextBox();
this.txtAction = new ACS.UI.Controls.TextBox();
this.lblDescription = new ACS.UI.Controls.Label();
this.lblAction = new ACS.UI.Controls.Label();
this.lblProtest = new ACS.UI.Controls.Label();
this.txtProtest = new ACS.UI.Controls.TextBox();
this.txtResolution = new ACS.UI.Controls.TextBox();
this.lblResolution = new ACS.UI.Controls.Label();
this.SuspendLayout();
//
// cmdCancel
//
this.cmdCancel.Location = new System.Drawing.Point(368, 408);
this.cmdCancel.Name = "cmdCancel";
//
// cmdOK
//
this.cmdOK.Location = new System.Drawing.Point(280, 409);
this.cmdOK.Name = "cmdOK";
//
// lblHorizontalLine
//
this.lblHorizontalLine.Location = new System.Drawing.Point(-8,
398);
this.lblHorizontalLine.Name = "lblHorizontalLine";
this.lblHorizontalLine.Size = new System.Drawing.Size(474, 3);
//
// lblMisDate
//
this.lblMisDate.Location = new System.Drawing.Point(8, 8);
this.lblMisDate.Name = "lblMisDate";
this.lblMisDate.Size = new System.Drawing.Size(112, 16);
this.lblMisDate.TabIndex = 57;
this.lblMisDate.Text = "Mistreatement Date:";
//
// dtpMistreatmentDate
//
this.dtpMistreatmentDate.CustomFormat = "dd-MMM-yyyy";
this.dtpMistreatmentDate.FormatEx =
ACS.UI.Controls.DateTimePickerCustomFormat.StandardNoTime;
this.dtpMistreatmentDate.Location = new System.Drawing.Point(8,
24);
this.dtpMistreatmentDate.Name = "dtpMistreatmentDate";
this.dtpMistreatmentDate.ReadOnly = false;
this.dtpMistreatmentDate.ShowButtons = true;
this.dtpMistreatmentDate.Size = new System.Drawing.Size(112, 20);
this.dtpMistreatmentDate.TabIndex = 58;
this.dtpMistreatmentDate.Value = new System.DateTime(1753, 1, 1,
15, 8, 40, 119);
//
// chkConfirmed
//
this.chkConfirmed.Location = new System.Drawing.Point(176, 24);
this.chkConfirmed.Name = "chkConfirmed";
this.chkConfirmed.Size = new System.Drawing.Size(80, 16);
this.chkConfirmed.TabIndex = 59;
this.chkConfirmed.Text = "Confirmed";
//
// chkProtest
//
this.chkProtest.Location = new System.Drawing.Point(312, 24);
this.chkProtest.Name = "chkProtest";
this.chkProtest.Size = new System.Drawing.Size(96, 16);
this.chkProtest.TabIndex = 60;
this.chkProtest.Text = "Protest Filed";
//
// txtDescript
//
this.txtDescript.AcceptsReturn = true;
this.txtDescript.Location = new System.Drawing.Point(8, 70);
this.txtDescript.Multiline = true;
this.txtDescript.Name = "txtDescript";
this.txtDescript.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.txtDescript.Size = new System.Drawing.Size(432, 112);
this.txtDescript.TabIndex = 61;
this.txtDescript.Text = "";
//
// txtAction
//
this.txtAction.Location = new System.Drawing.Point(8, 206);
this.txtAction.Multiline = true;
this.txtAction.Name = "txtAction";
this.txtAction.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.txtAction.Size = new System.Drawing.Size(200, 80);
this.txtAction.TabIndex = 62;
this.txtAction.Text = "";
//
// lblDescription
//
this.lblDescription.Location = new System.Drawing.Point(8, 54);
this.lblDescription.Name = "lblDescription";
this.lblDescription.Size = new System.Drawing.Size(64, 16);
this.lblDescription.TabIndex = 63;
this.lblDescription.Text = "Description:";
//
// lblAction
//
this.lblAction.Location = new System.Drawing.Point(8, 190);
this.lblAction.Name = "lblAction";
this.lblAction.Size = new System.Drawing.Size(88, 16);
this.lblAction.TabIndex = 64;
this.lblAction.Text = "Action Taken:";
//
// lblProtest
//
this.lblProtest.Location = new System.Drawing.Point(240, 190);
this.lblProtest.Name = "lblProtest";
this.lblProtest.Size = new System.Drawing.Size(88, 16);
this.lblProtest.TabIndex = 65;
this.lblProtest.Text = "How Protested:";
//
// txtProtest
//
this.txtProtest.Location = new System.Drawing.Point(240, 206);
this.txtProtest.Multiline = true;
this.txtProtest.Name = "txtProtest";
this.txtProtest.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.txtProtest.Size = new System.Drawing.Size(200, 80);
this.txtProtest.TabIndex = 66;
this.txtProtest.Text = "";
//
// txtResolution
//
this.txtResolution.Location = new System.Drawing.Point(8, 310);
this.txtResolution.Multiline = true;
this.txtResolution.Name = "txtResolution";
this.txtResolution.ScrollBars =
System.Windows.Forms.ScrollBars.Both;
this.txtResolution.Size = new System.Drawing.Size(432, 80);
this.txtResolution.TabIndex = 67;
this.txtResolution.Text = "";
//
// lblResolution
//
this.lblResolution.Location = new System.Drawing.Point(8, 294);
this.lblResolution.Name = "lblResolution";
this.lblResolution.Size = new System.Drawing.Size(72, 16);
this.lblResolution.TabIndex = 68;
this.lblResolution.Text = "Resolution:";
//
// MistreatmentForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(450, 447);
this.Controls.Add(this.lblResolution);
this.Controls.Add(this.txtResolution);
this.Controls.Add(this.txtProtest);
this.Controls.Add(this.lblProtest);
this.Controls.Add(this.lblAction);
this.Controls.Add(this.lblDescription);
this.Controls.Add(this.txtAction);
this.Controls.Add(this.txtDescript);
this.Controls.Add(this.chkProtest);
this.Controls.Add(this.chkConfirmed);
this.Controls.Add(this.dtpMistreatmentDate);
this.Controls.Add(this.lblMisDate);
this.Name = "MistreatmentForm";
this.Text = "ACS-Mistreatment";
this.Load += new System.EventHandler(this.MistreatmentForm_Load);
this.Controls.SetChildIndex(this.lblMisDate, 0);
this.Controls.SetChildIndex(this.dtpMistreatmentDate, 0);
this.Controls.SetChildIndex(this.chkConfirmed, 0);
this.Controls.SetChildIndex(this.chkProtest, 0);
this.Controls.SetChildIndex(this.txtDescript, 0);
this.Controls.SetChildIndex(this.txtAction, 0);
this.Controls.SetChildIndex(this.lblDescription, 0);
this.Controls.SetChildIndex(this.lblAction, 0);
this.Controls.SetChildIndex(this.lblProtest, 0);
this.Controls.SetChildIndex(this.txtProtest, 0);
this.Controls.SetChildIndex(this.txtResolution, 0);
this.Controls.SetChildIndex(this.lblResolution, 0);
this.Controls.SetChildIndex(this.lblHorizontalLine, 0);
this.Controls.SetChildIndex(this.cmdOK, 0);
this.Controls.SetChildIndex(this.cmdCancel, 0);
this.ResumeLayout(false);
}
#endregion
protected override void cmdOK_Click(object sender, System.EventArgs
e)
{
if (mMistreatmentList != null)
{
mMistreatmentList.Add(mMistreatment);
}
Close();
}
private void MistreatmentForm_Load(object sender, System.EventArgs
e)
{
BindMistreatment();
}
}
}