PC Review


Reply
Thread Tools Rate Thread

Binding to a date class property

 
 
Tim Delaney
Guest
Posts: n/a
 
      27th Aug 2003
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();

}


}
}
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Binding control property to class property? Johnny Jörgensen Microsoft C# .NET 5 3rd May 2007 09:22 AM
Binding to property of property of object collection TS Microsoft ASP .NET 3 31st Aug 2006 01:57 PM
Parse method never called when data binding from class property to textedit Richard Urwin Microsoft C# .NET 3 15th Oct 2004 04:42 AM
Parse method never called when data binding from class property to textedit Richard Urwin Microsoft Dot NET Framework Forms 1 14th Oct 2004 09:43 AM
Binding the Image property of the picturebox to a another class.property Cade Carvell Microsoft VB .NET 1 9th Jul 2003 05:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:53 AM.