Wire up a ComboBox.

D

dbuchanan

How do I wire up ComboBox to my data table to store my selection and to my
lookup table that allows me to make that selection:

Here is my attempt. Please correct me.

Configuration and DataBinding of the ComboBox...

DropDownStyle:
DropDownList

DataSource:
The bindingSource for the lookup table that I put in the component tray
"bsPhase"

Display Member:
The column of the lookup table that I want to display in the "Phase"

Value Member:
The column of the lookup table that contains the value that is linked to the
table that the form is bound to "pkPhaseID"

Selected Value:
What is this for?

---
DataBindings configuration properties of the ComboBox

(Name):
ComboBoxfkPhaseID

(DataBindings) (Advanced):
I don't think I need this.

(DataBindings) Selected Item:
What is this for?

(DataBindings) Selected Value:
What is this for? (? Shouldn't this be the target column of my main table?)

(DataBindings) Tag:
I don't think I need this.

(DataBindings) Text:
The BindingSource for the Main table and the column to bind it to "bsMTask -
fkPhaseID"
(? shouldn't this be the text of the lookup table I wish to display?)

Please tell me what I have missed.

Thank you,
Doug
 
L

Linda Liu [MSFT]

Hi Doug,

The ComboBox control supports complex data binding as well as simple data
binding.

When we set the DataSource property of a ComboBox control to a list data
source, e.g. a BindingSource, the ComboBox's items are populated by the
data source. If the BindingSource is bound to a DataSet/DataTable, the
items poplulated in the ComboBox is of the type DataRowView and the text
displayed in ComboBox is 'System.Data.DataRowView'. At this time, the value
of the SelectedItem as well as the SelectedValue property is of the type
DataRowView.

This is complex data binding and the DataTable mentioned above is the
so-called lookup table.

We could set the DisplayMember property of the ComboBox to a column in the
data source, thus the value of the column is displayed in the ComboBox. For
example:
this.comboBox1.DisplayMember = "Name";

We could also set the ValueMember property of the ComboBox to a column in
the data source, so that the SelectedValue property returns the value of
that column. For example:
this.comboBox1.ValueMember = "ID";

Now the value of the SelectedItem property is still of the type
DataRowView, but that of the SelectedValue property is of the same type as
the "ID" column.

We could bind the SelectedValue or Text property of the ComboBox to a
column in another data source, and this is simple data binding. Usually, we
bind the SelectedValue property rather than the Text property, because we
usually store int value for that column in database. For example, we have
two tables: CategoryTable(CategoryID int, CategoryName varchar) and
BusinessTable(BusinessID int, CategoryID int, .. ). As you see, we usually
store the int values of CategoryID in the BusinessTable rather than the
varchar values of CategoryName. So we bind the ComboBox like this:

this.comboBox1.DataSource = CategoryDataTable;
this.comboBox1.ValueMember = "CategoryID";
this.comboBox1.DisplayMember = "CategoryName";
this.comboBox1.DataBindings.Add("SelectedValue", BusinessDataTable,
"CategoryID");

Hope I make some clarification.
If you have any question, please feel free to let me now.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

dbuchanan

Linda,

I'm sorry, but I don't understand your answer. I spent more than an hour
trying to figure it out.

Basically in my first question I outlined the context of what I was trying
to do. I explained what I knew, what I did so far and what I didn't know.

You gave me a lot of theory. I could not follow it because it was outside
the context of things I am familar with. It used terms I and unfamilar with.
It approached the geneeral theory from different angles. I am unprepared to
meticulously deconstruct a complicated explanation when I cannot relate to
the terms and unfamiliar context.

For the purpose of helping you understand why I got confused please take a
look and my thoughts as I tried to make sense of your reply... (You do not
need to answer the questions below.)

==============================
If the BindingSource is bound to a DataSet/DataTable, the
items poplulated in the ComboBox is of the type DataRowView and the text
displayed in ComboBox is 'System.Data.DataRowView'.

What do you mean 'DataRowView'? and what do you mean
'System.Data.DataRowView'? No where do I see these terms in the properties
and no where in the code do I see it referr these terms. What do I do with
this information?

==============================
At this time, the value
of the SelectedItem as well as the SelectedValue property is of the type
DataRowView.

"At this time." What do you mean "At what time"? And what do you mean
'DataRowView'? same question as above.

==============================
This is complex data binding and the DataTable mentioned above is the
so-called lookup table.

It sure is complex!

==============================
We could set the DisplayMember property of the ComboBox to a column in the
data source, thus the value of the column is displayed in the ComboBox.
For
example:
this.comboBox1.DisplayMember = "Name";

Why do you say '.could.' (second word)? I told you what I was trying to do.
The theory about what I could do is confusing me. Does this somehow directly
apply to what I was asking?

You said about setting a property: ".to a column in the 'data source'.".
Which 'data source' are you talking about in this part? The lookup table? or
the main data table? I am confused because you are giving me examples that I
don' t know if they apply to my circumstances at hand.

". thus the value of the column." which column? The column of the lookup
table or the column of the main table?

==============================
We could also set the ValueMember property of the ComboBox to a column in
the data source, so that the SelectedValue property returns the value of
that column. For example:
this.comboBox1.ValueMember = "ID";

"Now the value." "We could set." "At this time." I am having a lot of
difficulty following your theory. You want me to suppose we do this, or
suppose we do that. You lose me by doing this.

I believe if you give me a simple explanation consistent to the context of
my question I would quickly come to eventually understand the theory anyway.

==============================
this.comboBox1.DataSource = CategoryDataTable;
this.comboBox1.ValueMember = "CategoryID";
this.comboBox1.DisplayMember = "CategoryName";
this.comboBox1.DataBindings.Add("SelectedValue", BusinessDataTable,
"CategoryID");

You give an example as if I were manually entering in the code. That does
not help me because that is not what I am doing. I am entering it into the
properties. I cannot relate easily relate to this.

I gave you a question in the context of my situation. You give me a reply
related to a totally different data. I can't make the translation.
==============================
==============================
==============================

Please look at my question again I have tried to simplify it...( I need a
simple answer.)

How do I wire up ComboBox so that when I make a comboBox selection, the
value member (ID in the lookup table) is stored in a kind of 'foreign key'
in my main data table?

Here is my attempt. Please correct me.

Configuration and DataBinding of the ComboBox...(appearing in ComboBox tasks
box)

DropDownStyle: DropDownList
DataSource: "bsPhase" (my lookup table)
Display Member: "Phase" (column of the lookup table that I want to display
to the user)
Value Member: "pkPhaseID" (The ID column of the lookup table that contains
the value that I want to store in my main table)
Selected Value: What is this for? ~ Should this be the binding source and
the value column that I wish to bind to the main table ("bsPhase -
pkPhaseID")?

---
DataBindings configuration properties of the ComboBox

(Name): ComboBoxfkPhaseID
(DataBindings) Selected Item: What is this for?
(DataBindings) Selected Value: (same as above in the ComboBox tasks box)
(DataBindings) Tag: I don't think I need this.
(DataBindings) Text: "bsMTask - fkPhaseID" (The BindingSource for the Main
table and the column to bind)

Please tell me what I have missed. What should I do?

Thank you,
Doug
 
L

Linda Liu [MSFT]

Hi Doug,

Thank you for your reply and detailed explanation!

I am terribly sorry making you confused. I was trying to explain the whole
thing step by step in my first reply.

Ok, I will answer your question directly : )
Selected Value: What is this for? ~ Should this be the binding source and
the value column that I wish to bind to the main table ("bsPhase -
pkPhaseID")?

The SelectedValue property gets or sets the value of the member property
specified by the ValueMember property. In your scenario, the SelectedValue
property returns the value of the "pkPhaseID" column in the lookup table.

To display the value of the "fkPhaseID" column of your main data table in
the ComboBox and save the changes in the ComboBox, if any, back to the
"fkPhaseID" column, you should bind the SelectedValue property to the
"fkPhaseID" column of your main data table.
(DataBindings) Selected Item: What is this for?

The SelectedItem property gets or sets currently selected item in the
ComboBox.
(DataBindings) Text: "bsMTask - fkPhaseID" (The BindingSource for the
Main
table and the column to bind)

No, you shouldn't bind the Text property to the "fkPhaseID" column of
bsMTask, instead, bind the SelectedValue property to the "fkPhaseID" column.

Hoep this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support
 
D

dbuchanan

Thank you Linda,

The comboBox now behaves as expected.

However I am getting another serious problem: After I make a change in the
comboBox the whole form locks up. I cannot interact with anything other
control on the form. I can however close that form using the "X" in the top
right corner of the form.

I tried several things to trouble shoot it but with no luck.

The main thing I did to trouble shoot was remove the event
"this.AnyControlChanged" from all controls. That made no difference. There
are no events except the button events and these do not work after the
comboBox has received input from the user.

Here is the autogenerated code:

// fkPhaseIDComboBox
//
this.fkPhaseIDComboBox.DataBindings.Add(new
System.Windows.Forms.Binding("Text", this.bsMTask, "fkPhaseID", true));
this.fkPhaseIDComboBox.DataBindings.Add(new
System.Windows.Forms.Binding("SelectedValue", this.bsMTask, "fkPhaseID",
true));
this.fkPhaseIDComboBox.DataSource = this.bsPhase;
this.fkPhaseIDComboBox.DisplayMember = "Phase";
this.fkPhaseIDComboBox.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList;
this.fkPhaseIDComboBox.FormattingEnabled = true;
this.fkPhaseIDComboBox.Location = new System.Drawing.Point(129,
68);
this.fkPhaseIDComboBox.Name = "fkPhaseIDComboBox";
this.fkPhaseIDComboBox.Size = new System.Drawing.Size(200, 21);
this.fkPhaseIDComboBox.TabIndex = 5;
this.fkPhaseIDComboBox.ValueMember = "pkPhaseID";
this.fkPhaseIDComboBox.TextChanged += new
System.EventHandler(this.AnyControlChanged);

Here are pertinent areas of my code:

public void InitialButtonSettings()
{
// Hide Save until records are edited.
this.btnSave.Enabled = false;
}

private void AnyControlChanged(object sender, EventArgs e)
{
//MessageBox.Show("Control changed");
this.btnSave.Enabled = true;
}

This is a very simple form. less than 100 lines of code with comments.
It uses visual inheritance, but that too is very simple.
What's up???

Total code below if you need to see it:
==The base class form designer code=======================
namespace HIP2007
{
partial class bsfAddEdit
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be
disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (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.btnNew = new System.Windows.Forms.Button();
this.btnDelete = new System.Windows.Forms.Button();
this.btnSave = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.lblDialogTitle = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// btnNew
//
this.btnNew.Anchor =
((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom
| System.Windows.Forms.AnchorStyles.Right)));
this.btnNew.Location = new System.Drawing.Point(134, 409);
this.btnNew.Name = "btnNew";
this.btnNew.Size = new System.Drawing.Size(75, 23);
this.btnNew.TabIndex = 0;
this.btnNew.Text = "New";
this.btnNew.UseVisualStyleBackColor = true;
this.btnNew.Click += new System.EventHandler(this.btnNew_Click);
//
// btnDelete
//
this.btnDelete.Anchor =
((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom
| System.Windows.Forms.AnchorStyles.Right)));
this.btnDelete.Location = new System.Drawing.Point(215, 409);
this.btnDelete.Name = "btnDelete";
this.btnDelete.Size = new System.Drawing.Size(75, 23);
this.btnDelete.TabIndex = 1;
this.btnDelete.Text = "Delete";
this.btnDelete.UseVisualStyleBackColor = true;
this.btnDelete.Click += new
System.EventHandler(this.btnDelete_Click);
//
// btnSave
//
this.btnSave.Anchor =
((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom
| System.Windows.Forms.AnchorStyles.Right)));
this.btnSave.Location = new System.Drawing.Point(296, 409);
this.btnSave.Name = "btnSave";
this.btnSave.Size = new System.Drawing.Size(75, 23);
this.btnSave.TabIndex = 2;
this.btnSave.Text = "Save";
this.btnSave.UseVisualStyleBackColor = true;
this.btnSave.Click += new
System.EventHandler(this.btnSave_Click);
//
// btnCancel
//
this.btnCancel.Anchor =
((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom
| System.Windows.Forms.AnchorStyles.Right)));
this.btnCancel.Location = new System.Drawing.Point(377, 409);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(75, 23);
this.btnCancel.TabIndex = 3;
this.btnCancel.Text = "Cancel";
this.btnCancel.UseVisualStyleBackColor = true;
this.btnCancel.Click += new
System.EventHandler(this.btnCancel_Click);
//
// lblDialogTitle
//
this.lblDialogTitle.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.lblDialogTitle.Font = new System.Drawing.Font("Microsoft
Sans Serif", 12F, System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblDialogTitle.Location = new System.Drawing.Point(12, 9);
this.lblDialogTitle.Name = "lblDialogTitle";
this.lblDialogTitle.Size = new System.Drawing.Size(318, 30);
this.lblDialogTitle.TabIndex = 4;
this.lblDialogTitle.Text = "Dialog Title";
this.lblDialogTitle.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft;
//
// bsfAddEdit
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(464, 444);
this.Controls.Add(this.lblDialogTitle);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnSave);
this.Controls.Add(this.btnDelete);
this.Controls.Add(this.btnNew);
this.FormBorderStyle =
System.Windows.Forms.FormBorderStyle.FixedDialog;
this.HelpButton = true;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "bsfAddEdit";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition =
System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Dialog";
this.TopMost = true;
this.ResumeLayout(false);

}

#endregion

protected System.Windows.Forms.Label lblDialogTitle;
protected System.Windows.Forms.Button btnNew;
protected System.Windows.Forms.Button btnDelete;
protected System.Windows.Forms.Button btnSave;
protected System.Windows.Forms.Button btnCancel;
}
}
================================================
==The base class form code=============================
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace HIP2007
{
public partial class bsfAddEdit : Form
{
public bsfAddEdit()
{
InitializeComponent();
}
#region [ base Buttons
private void btnCancel_Click(object sender, EventArgs e)
{
// Close without save
Close();
}
private void btnSave_Click(object sender, EventArgs e)
{

}
private void btnDelete_Click(object sender, EventArgs e)
{

}
private void btnNew_Click(object sender, EventArgs e)
{

}
#endregion
}
}
================================================
==The derived class from designer class=====================
namespace HIP2007
{
partial class AddEditMasterTask
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be
disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (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.components = new System.ComponentModel.Container();
System.Windows.Forms.Label pkMTaskIDLabel;
System.Windows.Forms.Label descriptionLabel;
System.Windows.Forms.Label baseTimeLabel;
System.Windows.Forms.Label allowParticipationLabel;
System.Windows.Forms.Label allowQuantityLabel;
System.Windows.Forms.Label ordLabel;
System.Windows.Forms.Label configuredDisplayLabel;
System.Windows.Forms.Label contractorCommentsLabel;
System.Windows.Forms.Label modifiedDateLabel;
System.Windows.Forms.Label fkMeasureDimIDLabel;
System.Windows.Forms.Label fkMeasureUnitIDLabel;
System.Windows.Forms.Label fkPhaseIDLabel1;
this.dataSetHipAdmin = new HIPAdminAccess.DataSetHipAdmin();
this.bsMTask = new
System.Windows.Forms.BindingSource(this.components);
this.pkMTaskIDTextBox = new System.Windows.Forms.TextBox();
this.descriptionTextBox = new System.Windows.Forms.TextBox();
this.baseTimeTextBox = new System.Windows.Forms.TextBox();
this.allowParticipationCheckBox = new
System.Windows.Forms.CheckBox();
this.allowQuantityCheckBox = new
System.Windows.Forms.CheckBox();
this.ordTextBox = new System.Windows.Forms.TextBox();
this.configuredDisplayCheckBox = new
System.Windows.Forms.CheckBox();
this.contractorCommentsTextBox = new
System.Windows.Forms.TextBox();
this.modifiedDateDateTimePicker = new
System.Windows.Forms.DateTimePicker();
this.taMTask = new
HIPAdminAccess.DataSetHipAdminTableAdapters.MTaskTableAdapter();
this.taMeasureUnit = new
HIPAdminAccess.DataSetHipAdminTableAdapters.MeasureUnitTableAdapter();
this.taMeasureDim = new
HIPAdminAccess.DataSetHipAdminTableAdapters.MeasureDimTableAdapter();
this.bsMeasureDim = new
System.Windows.Forms.BindingSource(this.components);
this.bsMeasureUnit = new
System.Windows.Forms.BindingSource(this.components);
this.fkMeasureDimIDComboBox = new
System.Windows.Forms.ComboBox();
this.fkMeasureUnitIDComboBox = new
System.Windows.Forms.ComboBox();
this.toolTip1 = new
System.Windows.Forms.ToolTip(this.components);
this.fkPhaseIDComboBox = new System.Windows.Forms.ComboBox();
this.bsPhase = new
System.Windows.Forms.BindingSource(this.components);
this.taPhase = new
HIPAdminAccess.DataSetHipAdminTableAdapters.PhaseTableAdapter();
pkMTaskIDLabel = new System.Windows.Forms.Label();
descriptionLabel = new System.Windows.Forms.Label();
baseTimeLabel = new System.Windows.Forms.Label();
allowParticipationLabel = new System.Windows.Forms.Label();
allowQuantityLabel = new System.Windows.Forms.Label();
ordLabel = new System.Windows.Forms.Label();
configuredDisplayLabel = new System.Windows.Forms.Label();
contractorCommentsLabel = new System.Windows.Forms.Label();
modifiedDateLabel = new System.Windows.Forms.Label();
fkMeasureDimIDLabel = new System.Windows.Forms.Label();
fkMeasureUnitIDLabel = new System.Windows.Forms.Label();
fkPhaseIDLabel1 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.dataSetHipAdmin)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.bsMTask)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.bsMeasureDim)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.bsMeasureUnit)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.bsPhase)).BeginInit();
this.SuspendLayout();
//
// lblDialogTitle
//
this.lblDialogTitle.TabIndex = 1;
//
// btnNew
//
this.btnNew.Location = new System.Drawing.Point(282, 421);
this.btnNew.TabIndex = 27;
this.btnNew.Click += new System.EventHandler(this.btnNew_Click);
//
// btnDelete
//
this.btnDelete.Location = new System.Drawing.Point(363, 421);
this.btnDelete.TabIndex = 28;
this.btnDelete.Click += new
System.EventHandler(this.btnDelete_Click);
//
// btnSave
//
this.btnSave.Location = new System.Drawing.Point(444, 421);
this.btnSave.TabIndex = 26;
this.btnSave.Click += new
System.EventHandler(this.btnSave_Click);
//
// btnCancel
//
this.btnCancel.Location = new System.Drawing.Point(525, 421);
this.btnCancel.TabIndex = 0;
this.btnCancel.Click += new
System.EventHandler(this.btnCancel_Click);
//
// pkMTaskIDLabel
//
pkMTaskIDLabel.AutoSize = true;
pkMTaskIDLabel.Location = new System.Drawing.Point(12, 45);
pkMTaskIDLabel.Name = "pkMTaskIDLabel";
pkMTaskIDLabel.Size = new System.Drawing.Size(72, 13);
pkMTaskIDLabel.TabIndex = 2;
pkMTaskIDLabel.Text = "pk MTask ID:";
pkMTaskIDLabel.Visible = false;
//
// descriptionLabel
//
descriptionLabel.AutoSize = true;
descriptionLabel.Location = new System.Drawing.Point(12, 97);
descriptionLabel.Name = "descriptionLabel";
descriptionLabel.Size = new System.Drawing.Size(63, 13);
descriptionLabel.TabIndex = 6;
descriptionLabel.Text = "Description:";
//
// baseTimeLabel
//
baseTimeLabel.AutoSize = true;
baseTimeLabel.Location = new System.Drawing.Point(12, 175);
baseTimeLabel.Name = "baseTimeLabel";
baseTimeLabel.Size = new System.Drawing.Size(60, 13);
baseTimeLabel.TabIndex = 12;
baseTimeLabel.Text = "Base Time:";
//
// allowParticipationLabel
//
allowParticipationLabel.AutoSize = true;
allowParticipationLabel.Location = new System.Drawing.Point(12,
203);
allowParticipationLabel.Name = "allowParticipationLabel";
allowParticipationLabel.Size = new System.Drawing.Size(96, 13);
allowParticipationLabel.TabIndex = 14;
allowParticipationLabel.Text = "Allow Participation:";
//
// allowQuantityLabel
//
allowQuantityLabel.AutoSize = true;
allowQuantityLabel.Location = new System.Drawing.Point(12, 233);
allowQuantityLabel.Name = "allowQuantityLabel";
allowQuantityLabel.Size = new System.Drawing.Size(77, 13);
allowQuantityLabel.TabIndex = 16;
allowQuantityLabel.Text = "Allow Quantity:";
//
// ordLabel
//
ordLabel.AutoSize = true;
ordLabel.Location = new System.Drawing.Point(13, 261);
ordLabel.Name = "ordLabel";
ordLabel.Size = new System.Drawing.Size(27, 13);
ordLabel.TabIndex = 18;
ordLabel.Text = "Ord:";
//
// configuredDisplayLabel
//
configuredDisplayLabel.AutoSize = true;
configuredDisplayLabel.Location = new System.Drawing.Point(12,
289);
configuredDisplayLabel.Name = "configuredDisplayLabel";
configuredDisplayLabel.Size = new System.Drawing.Size(98, 13);
configuredDisplayLabel.TabIndex = 20;
configuredDisplayLabel.Text = "Configured Display:";
//
// contractorCommentsLabel
//
contractorCommentsLabel.AutoSize = true;
contractorCommentsLabel.Location = new System.Drawing.Point(12,
317);
contractorCommentsLabel.Name = "contractorCommentsLabel";
contractorCommentsLabel.Size = new System.Drawing.Size(111, 13);
contractorCommentsLabel.TabIndex = 22;
contractorCommentsLabel.Text = "Contractor Comments:";
//
// modifiedDateLabel
//
modifiedDateLabel.AutoSize = true;
modifiedDateLabel.Location = new System.Drawing.Point(12, 370);
modifiedDateLabel.Name = "modifiedDateLabel";
modifiedDateLabel.Size = new System.Drawing.Size(76, 13);
modifiedDateLabel.TabIndex = 24;
modifiedDateLabel.Text = "Modified Date:";
//
// fkMeasureDimIDLabel
//
fkMeasureDimIDLabel.AutoSize = true;
fkMeasureDimIDLabel.Location = new System.Drawing.Point(12,
123);
fkMeasureDimIDLabel.Name = "fkMeasureDimIDLabel";
fkMeasureDimIDLabel.Size = new System.Drawing.Size(59, 13);
fkMeasureDimIDLabel.TabIndex = 8;
fkMeasureDimIDLabel.Text = "Dimension:";
//
// fkMeasureUnitIDLabel
//
fkMeasureUnitIDLabel.AutoSize = true;
fkMeasureUnitIDLabel.Location = new System.Drawing.Point(11,
149);
fkMeasureUnitIDLabel.Name = "fkMeasureUnitIDLabel";
fkMeasureUnitIDLabel.Size = new System.Drawing.Size(29, 13);
fkMeasureUnitIDLabel.TabIndex = 10;
fkMeasureUnitIDLabel.Text = "Unit:";
//
// fkPhaseIDLabel1
//
fkPhaseIDLabel1.AutoSize = true;
fkPhaseIDLabel1.Location = new System.Drawing.Point(12, 71);
fkPhaseIDLabel1.Name = "fkPhaseIDLabel1";
fkPhaseIDLabel1.Size = new System.Drawing.Size(40, 13);
fkPhaseIDLabel1.TabIndex = 4;
fkPhaseIDLabel1.Text = "Phase:";
//
// dataSetHipAdmin
//
this.dataSetHipAdmin.DataSetName = "DataSetHipAdmin";
this.dataSetHipAdmin.SchemaSerializationMode =
System.Data.SchemaSerializationMode.IncludeSchema;
//
// bsMTask
//
this.bsMTask.DataMember = "MTask";
this.bsMTask.DataSource = this.dataSetHipAdmin;
//
// pkMTaskIDTextBox
//
this.pkMTaskIDTextBox.DataBindings.Add(new
System.Windows.Forms.Binding("Text", this.bsMTask, "pkMTaskID", true));
this.pkMTaskIDTextBox.Location = new System.Drawing.Point(129,
42);
this.pkMTaskIDTextBox.Name = "pkMTaskIDTextBox";
this.pkMTaskIDTextBox.Size = new System.Drawing.Size(200, 20);
this.pkMTaskIDTextBox.TabIndex = 3;
this.pkMTaskIDTextBox.Visible = false;
//
// descriptionTextBox
//
this.descriptionTextBox.DataBindings.Add(new
System.Windows.Forms.Binding("Text", this.bsMTask, "Description", true));
this.descriptionTextBox.Location = new System.Drawing.Point(129,
94);
this.descriptionTextBox.Name = "descriptionTextBox";
this.descriptionTextBox.Size = new System.Drawing.Size(400, 20);
this.descriptionTextBox.TabIndex = 7;
//
// baseTimeTextBox
//
this.baseTimeTextBox.DataBindings.Add(new
System.Windows.Forms.Binding("Text", this.bsMTask, "BaseTime", true));
this.baseTimeTextBox.Location = new System.Drawing.Point(129,
172);
this.baseTimeTextBox.Name = "baseTimeTextBox";
this.baseTimeTextBox.Size = new System.Drawing.Size(50, 20);
this.baseTimeTextBox.TabIndex = 13;
this.toolTip1.SetToolTip(this.baseTimeTextBox, "The time for
each unit of dimensional unit.");
//
// allowParticipationCheckBox
//
this.allowParticipationCheckBox.DataBindings.Add(new
System.Windows.Forms.Binding("CheckState", this.bsMTask,
"AllowParticipation", true));
this.allowParticipationCheckBox.Location = new
System.Drawing.Point(129, 198);
this.allowParticipationCheckBox.Name =
"allowParticipationCheckBox";
this.allowParticipationCheckBox.Size = new
System.Drawing.Size(50, 24);
this.allowParticipationCheckBox.TabIndex = 15;
//
// allowQuantityCheckBox
//
this.allowQuantityCheckBox.DataBindings.Add(new
System.Windows.Forms.Binding("CheckState", this.bsMTask, "AllowQuantity",
true));
this.allowQuantityCheckBox.Location = new
System.Drawing.Point(129, 228);
this.allowQuantityCheckBox.Name = "allowQuantityCheckBox";
this.allowQuantityCheckBox.Size = new System.Drawing.Size(50,
24);
this.allowQuantityCheckBox.TabIndex = 17;
//
// ordTextBox
//
this.ordTextBox.DataBindings.Add(new
System.Windows.Forms.Binding("Text", this.bsMTask, "Ord", true));
this.ordTextBox.Location = new System.Drawing.Point(129, 258);
this.ordTextBox.Name = "ordTextBox";
this.ordTextBox.Size = new System.Drawing.Size(50, 20);
this.ordTextBox.TabIndex = 19;
this.toolTip1.SetToolTip(this.ordTextBox, "The order in which
this task appears within the same phase.");
//
// configuredDisplayCheckBox
//
this.configuredDisplayCheckBox.DataBindings.Add(new
System.Windows.Forms.Binding("CheckState", this.bsMTask,
"ConfiguredDisplay", true));
this.configuredDisplayCheckBox.Location = new
System.Drawing.Point(129, 284);
this.configuredDisplayCheckBox.Name =
"configuredDisplayCheckBox";
this.configuredDisplayCheckBox.Size = new
System.Drawing.Size(50, 24);
this.configuredDisplayCheckBox.TabIndex = 21;
//
// contractorCommentsTextBox
//
this.contractorCommentsTextBox.DataBindings.Add(new
System.Windows.Forms.Binding("Text", this.bsMTask, "ContractorComments",
true));
this.contractorCommentsTextBox.Location = new
System.Drawing.Point(129, 314);
this.contractorCommentsTextBox.Multiline = true;
this.contractorCommentsTextBox.Name =
"contractorCommentsTextBox";
this.contractorCommentsTextBox.Size = new
System.Drawing.Size(400, 46);
this.contractorCommentsTextBox.TabIndex = 23;
//
// modifiedDateDateTimePicker
//
this.modifiedDateDateTimePicker.DataBindings.Add(new
System.Windows.Forms.Binding("Value", this.bsMTask, "ModifiedDate", true));
this.modifiedDateDateTimePicker.Enabled = false;
this.modifiedDateDateTimePicker.Location = new
System.Drawing.Point(129, 366);
this.modifiedDateDateTimePicker.Name =
"modifiedDateDateTimePicker";
this.modifiedDateDateTimePicker.Size = new
System.Drawing.Size(200, 20);
this.modifiedDateDateTimePicker.TabIndex = 25;
//
// taMTask
//
this.taMTask.ClearBeforeFill = true;
//
// taMeasureUnit
//
this.taMeasureUnit.ClearBeforeFill = true;
//
// taMeasureDim
//
this.taMeasureDim.ClearBeforeFill = true;
//
// bsMeasureDim
//
this.bsMeasureDim.DataMember = "MeasureDim";
this.bsMeasureDim.DataSource = this.dataSetHipAdmin;
this.bsMeasureDim.Sort = "ord";
//
// bsMeasureUnit
//
this.bsMeasureUnit.DataMember = "FK_MeasureUnit_MeasureDim";
this.bsMeasureUnit.DataSource = this.bsMeasureDim;
this.bsMeasureUnit.Sort = "ord";
//
// fkMeasureDimIDComboBox
//
this.fkMeasureDimIDComboBox.DataBindings.Add(new
System.Windows.Forms.Binding("Text", this.bsMTask, "fkMeasureDimID", true));
this.fkMeasureDimIDComboBox.DataBindings.Add(new
System.Windows.Forms.Binding("SelectedValue", this.bsMTask,
"fkMeasureDimID", true));
this.fkMeasureDimIDComboBox.DataSource = this.bsMeasureDim;
this.fkMeasureDimIDComboBox.DisplayMember = "Dimension";
this.fkMeasureDimIDComboBox.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList;
this.fkMeasureDimIDComboBox.FormattingEnabled = true;
this.fkMeasureDimIDComboBox.Location = new
System.Drawing.Point(129, 120);
this.fkMeasureDimIDComboBox.Name = "fkMeasureDimIDComboBox";
this.fkMeasureDimIDComboBox.Size = new System.Drawing.Size(200,
21);
this.fkMeasureDimIDComboBox.TabIndex = 9;
this.fkMeasureDimIDComboBox.ValueMember = "pkMeasureDimID";
//
// fkMeasureUnitIDComboBox
//
this.fkMeasureUnitIDComboBox.DataBindings.Add(new
System.Windows.Forms.Binding("Text", this.bsMTask, "fkMeasureUnitID",
true));
this.fkMeasureUnitIDComboBox.DataBindings.Add(new
System.Windows.Forms.Binding("SelectedValue", this.bsMTask,
"fkMeasureUnitID", true));
this.fkMeasureUnitIDComboBox.DataSource = this.bsMeasureUnit;
this.fkMeasureUnitIDComboBox.DisplayMember = "Unit";
this.fkMeasureUnitIDComboBox.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList;
this.fkMeasureUnitIDComboBox.FormattingEnabled = true;
this.fkMeasureUnitIDComboBox.Location = new
System.Drawing.Point(129, 146);
this.fkMeasureUnitIDComboBox.Name = "fkMeasureUnitIDComboBox";
this.fkMeasureUnitIDComboBox.Size = new System.Drawing.Size(200,
21);
this.fkMeasureUnitIDComboBox.TabIndex = 11;
this.fkMeasureUnitIDComboBox.ValueMember = "pkMeasureUnitID";
//
// fkPhaseIDComboBox
//
this.fkPhaseIDComboBox.DataBindings.Add(new
System.Windows.Forms.Binding("Text", this.bsMTask, "fkPhaseID", true));
this.fkPhaseIDComboBox.DataBindings.Add(new
System.Windows.Forms.Binding("SelectedValue", this.bsMTask, "fkPhaseID",
true));
this.fkPhaseIDComboBox.DataSource = this.bsPhase;
this.fkPhaseIDComboBox.DisplayMember = "Phase";
this.fkPhaseIDComboBox.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList;
this.fkPhaseIDComboBox.FormattingEnabled = true;
this.fkPhaseIDComboBox.Location = new System.Drawing.Point(129,
68);
this.fkPhaseIDComboBox.Name = "fkPhaseIDComboBox";
this.fkPhaseIDComboBox.Size = new System.Drawing.Size(200, 21);
this.fkPhaseIDComboBox.TabIndex = 5;
this.fkPhaseIDComboBox.ValueMember = "pkPhaseID";
//
// bsPhase
//
this.bsPhase.DataMember = "Phase";
this.bsPhase.DataSource = this.dataSetHipAdmin;
this.bsPhase.Sort = "ord";
//
// taPhase
//
this.taPhase.ClearBeforeFill = true;
//
// AddEditMasterTask
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(612, 456);
this.Controls.Add(fkPhaseIDLabel1);
this.Controls.Add(this.fkPhaseIDComboBox);
this.Controls.Add(fkMeasureUnitIDLabel);
this.Controls.Add(this.fkMeasureUnitIDComboBox);
this.Controls.Add(fkMeasureDimIDLabel);
this.Controls.Add(this.fkMeasureDimIDComboBox);
this.Controls.Add(pkMTaskIDLabel);
this.Controls.Add(this.pkMTaskIDTextBox);
this.Controls.Add(descriptionLabel);
this.Controls.Add(this.descriptionTextBox);
this.Controls.Add(baseTimeLabel);
this.Controls.Add(this.baseTimeTextBox);
this.Controls.Add(allowParticipationLabel);
this.Controls.Add(this.allowParticipationCheckBox);
this.Controls.Add(allowQuantityLabel);
this.Controls.Add(this.allowQuantityCheckBox);
this.Controls.Add(ordLabel);
this.Controls.Add(this.ordTextBox);
this.Controls.Add(configuredDisplayLabel);
this.Controls.Add(this.configuredDisplayCheckBox);
this.Controls.Add(contractorCommentsLabel);
this.Controls.Add(this.contractorCommentsTextBox);
this.Controls.Add(modifiedDateLabel);
this.Controls.Add(this.modifiedDateDateTimePicker);
this.Name = "AddEditMasterTask";
this.Text = "AddEditMTask";
this.Controls.SetChildIndex(this.btnNew, 0);
this.Controls.SetChildIndex(this.btnDelete, 0);
this.Controls.SetChildIndex(this.btnSave, 0);
this.Controls.SetChildIndex(this.btnCancel, 0);
this.Controls.SetChildIndex(this.lblDialogTitle, 0);
this.Controls.SetChildIndex(this.modifiedDateDateTimePicker, 0);
this.Controls.SetChildIndex(modifiedDateLabel, 0);
this.Controls.SetChildIndex(this.contractorCommentsTextBox, 0);
this.Controls.SetChildIndex(contractorCommentsLabel, 0);
this.Controls.SetChildIndex(this.configuredDisplayCheckBox, 0);
this.Controls.SetChildIndex(configuredDisplayLabel, 0);
this.Controls.SetChildIndex(this.ordTextBox, 0);
this.Controls.SetChildIndex(ordLabel, 0);
this.Controls.SetChildIndex(this.allowQuantityCheckBox, 0);
this.Controls.SetChildIndex(allowQuantityLabel, 0);
this.Controls.SetChildIndex(this.allowParticipationCheckBox, 0);
this.Controls.SetChildIndex(allowParticipationLabel, 0);
this.Controls.SetChildIndex(this.baseTimeTextBox, 0);
this.Controls.SetChildIndex(baseTimeLabel, 0);
this.Controls.SetChildIndex(this.descriptionTextBox, 0);
this.Controls.SetChildIndex(descriptionLabel, 0);
this.Controls.SetChildIndex(this.pkMTaskIDTextBox, 0);
this.Controls.SetChildIndex(pkMTaskIDLabel, 0);
this.Controls.SetChildIndex(this.fkMeasureDimIDComboBox, 0);
this.Controls.SetChildIndex(fkMeasureDimIDLabel, 0);
this.Controls.SetChildIndex(this.fkMeasureUnitIDComboBox, 0);
this.Controls.SetChildIndex(fkMeasureUnitIDLabel, 0);
this.Controls.SetChildIndex(this.fkPhaseIDComboBox, 0);
this.Controls.SetChildIndex(fkPhaseIDLabel1, 0);
((System.ComponentModel.ISupportInitialize)(this.dataSetHipAdmin)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.bsMTask)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.bsMeasureDim)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.bsMeasureUnit)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.bsPhase)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private HIPAdminAccess.DataSetHipAdmin dataSetHipAdmin;
private System.Windows.Forms.BindingSource bsMTask;
private System.Windows.Forms.TextBox pkMTaskIDTextBox;
private System.Windows.Forms.TextBox descriptionTextBox;
private System.Windows.Forms.TextBox baseTimeTextBox;
private System.Windows.Forms.CheckBox allowParticipationCheckBox;
private System.Windows.Forms.CheckBox allowQuantityCheckBox;
private System.Windows.Forms.TextBox ordTextBox;
private System.Windows.Forms.CheckBox configuredDisplayCheckBox;
private System.Windows.Forms.TextBox contractorCommentsTextBox;
private System.Windows.Forms.DateTimePicker
modifiedDateDateTimePicker;
private
HIPAdminAccess.DataSetHipAdminTableAdapters.MTaskTableAdapter taMTask;
private System.Windows.Forms.BindingSource bsMeasureDim;
private System.Windows.Forms.BindingSource bsMeasureUnit;
private
HIPAdminAccess.DataSetHipAdminTableAdapters.MeasureUnitTableAdapter
taMeasureUnit;
private
HIPAdminAccess.DataSetHipAdminTableAdapters.MeasureDimTableAdapter
taMeasureDim;
private System.Windows.Forms.ComboBox fkMeasureDimIDComboBox;
private System.Windows.Forms.ComboBox fkMeasureUnitIDComboBox;
private System.Windows.Forms.ToolTip toolTip1;
private System.Windows.Forms.ComboBox fkPhaseIDComboBox;
private System.Windows.Forms.BindingSource bsPhase;
private
HIPAdminAccess.DataSetHipAdminTableAdapters.PhaseTableAdapter taPhase;
}
}
================================================
==The derived class form code===========================
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace HIP2007
{
public partial class AddEditMasterTask : bsfAddEdit
{
public AddEditMasterTask()
{
InitializeComponent();

// form title
this.Text = "";

// Title
lblDialogTitle.Text = "Add Master Task";

// Set buttons
InitialButtonSettings();

// Open Dropdowns
taPhase.Fill(dataSetHipAdmin.Phase);
taMeasureDim.Fill(dataSetHipAdmin.MeasureDim);
taMeasureUnit.Fill(dataSetHipAdmin.MeasureUnit);

// Open
taMTask.Fill(dataSetHipAdmin.MTask);

}

#region [ Control of buttons

public void InitialButtonSettings()
{
// Hide Save
this.btnSave.Enabled = false;

// If no records hide the
}

//public void EditBegun()
//{
// // Button scheme after edits begin
// this.btnSave.Enabled = true;
// this.btnNew.Enabled = false;
//}

//private void AnyControlChanged(object sender, EventArgs e)
//{
// //MessageBox.Show("ComboBox changed");
// this.btnSave.Enabled = true;
// this.btnNew.Enabled = false;
//}

#endregion

#region [ Buttons

private void btnNew_Click(object sender, EventArgs e)
{
//Clear the current record
MessageBox.Show("New");
}

private void btnDelete_Click(object sender, EventArgs e)
{
// Delete the current record
MessageBox.Show("Delete");
}

private void btnSave_Click(object sender, EventArgs e)
{
// Save the current record
bsMTask.EndEdit();
taMTask.Update(dataSetHipAdmin.MTask);
this.Close();
}

private void btnCancel_Click(object sender, EventArgs e)
{
// Close without saving
this.Close();
}

#endregion

}
}
================================================
 
L

Linda Liu [MSFT]

Hi Doug,

Thank you for your reply!

I notice that you bind both the Text property and the SelectedValue
property of the fkPhaseIDComboBox to the "fkPhaseID" column of the main
table.

Please remove the data binding to the Text property to see if the problem
still exists. In addition, I suggest you to subscribe the
SelectedValueChanged event of the fkPhaseIDComboBox instead of the
TextChanged event. For example:

this.comboBox1.SelectedValueChanged += new
EventHandler(comboBox1_SelectedValueChanged);
void comboBox1_SelectedValueChanged(object sender, EventArgs e)
{
this.btnSave.Enabled = true;
}

If the problem still exists, please send me a simple project that could
just reproduce the problem. To get my actual email address, remove 'online'
from my displayed email address.

Sincerely,
Linda Liu
Microsoft Online Community Support
 
D

dbuchanan

Hi Linda
Removeing the binding to the text property resolved the problem.

Thank you very much.
Doug
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top