By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,825 Members | 1,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,825 IT Pros & Developers. It's quick & easy.

ComboBox DateTimePicker Binding Focus Bug / Mess

P: n/a
I've come across an interesting bug.
I have workarounds but i'd like to know the root of the problem. I've
stripped it down into a short file and hope someone might have an idea about
what's going on.

It's a simple program that loads a control onto a form and binds "Foo"
against a combobox ("SelectedItem") for it's "Bar" property and a
datetimepicker ("Value") for it's "DateTime" property. The
DateTimePicker.Visible value is set to false.
Once it's loaded up, select the combobox and then attempt to deselect it by
selecting the checkbox. This is rendered impossible by the combobox
retaining the focus, you cannot even close the form, such is it's grasp on
the focus.

I have found three ways of fixing this problem.

a) Remove the binding to Bar (a bit obvious)
b) Remove the binding to DateTime
c) Make the DateTimePicker visible !?!

I'm currently running Win2k. And .NET 2.00, I think 1.1 has the same
problem.
Code is below.

// SEARCH TAGS: Combobox Focus Bug Binding Datetimepicker.Value
DateTimePicker.Visible

// CODE BEGINS

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication6
{
public class Bar
{
public Bar()
{
}
}

public class Foo
{
private Bar m_Bar = new Bar();
private DateTime m_DateTime = DateTime.Now;

public Foo()
{
}

public Bar Bar
{
get
{
return m_Bar;
}
set
{
m_Bar = value;
}
}

public DateTime DateTime
{
get
{
return m_DateTime;
}
set
{
m_DateTime = value;
}
}
}

public class TestBugControl : UserControl
{
public TestBugControl()
{
InitializeComponent();
}

public void InitializeData(IList types)
{
this.cBoxType.DataSource = types;
}

public void BindFoo(Foo foo)
{
this.cBoxType.DataBindings.Add("SelectedItem", foo, "Bar");
this.dtStart.DataBindings.Add("Value", foo, "DateTime");
}

/// <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 Component 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.checkBox1 = new System.Windows.Forms.CheckBox();
this.cBoxType = new System.Windows.Forms.ComboBox();
this.dtStart = new System.Windows.Forms.DateTimePicker();
this.SuspendLayout();
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(14, 5);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(97, 20);
this.checkBox1.TabIndex = 0;
this.checkBox1.Text = "checkBox1";
this.checkBox1.UseVisualStyleBackColor = true;
//
// cBoxType
//
this.cBoxType.FormattingEnabled = true;
this.cBoxType.Location = new System.Drawing.Point(117, 3);
this.cBoxType.Name = "cBoxType";
this.cBoxType.Size = new System.Drawing.Size(165, 24);
this.cBoxType.TabIndex = 1;
//
// dtStart
//
this.dtStart.Location = new System.Drawing.Point(117, 40);
this.dtStart.Name = "dtStart";
this.dtStart.Size = new System.Drawing.Size(165, 23);
this.dtStart.TabIndex = 2;
this.dtStart.Visible = false;
//
// TestBugControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.dtStart);
this.Controls.Add(this.cBoxType);
this.Controls.Add(this.checkBox1);
this.Font = new System.Drawing.Font("Verdana", 9.75F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
((byte)(0)));
this.Margin = new System.Windows.Forms.Padding(4);
this.Name = "TestBugControl";
this.Size = new System.Drawing.Size(285, 66);
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.ComboBox cBoxType;
private System.Windows.Forms.DateTimePicker dtStart;
}

public class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Load += new EventHandler(Form1_Load);
}

void Form1_Load(object sender, EventArgs e)
{
InitializeControl();
}

public void InitializeControl()
{
TestBugControl control = new TestBugControl();
IList list = new ArrayList();
for (int i = 0; i < 10; i++)
{
list.Add(new Bar());
}
control.InitializeData(list);
control.BindFoo(new Foo());
this.Controls.Add(control);
}

/// <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();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Text = "Form1";
}

#endregion
}

static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new Form1());
}
}
}
Mar 13 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
VJ
I tried adding your user control add design time, and then assigning values
at load it worked, without any of your workaround.. Create, add the control
to form and then assign values to it. That order also works. Some how
creating, assigning and adding to Form fails.. Interesting situation, I will
see if I can find time later to work this. Let me know if you learn anything
new..

Bottom of problem, maybe Microsoft can answer?..

VJ

"Simon Tamman" <i_**********************************@NOSPAMhotmai l.com>
wrote in message news:st*************@newsfe4-gui.ntli.net...
I've come across an interesting bug.
I have workarounds but i'd like to know the root of the problem. I've
stripped it down into a short file and hope someone might have an idea
about
what's going on.

It's a simple program that loads a control onto a form and binds "Foo"
against a combobox ("SelectedItem") for it's "Bar" property and a
datetimepicker ("Value") for it's "DateTime" property. The
DateTimePicker.Visible value is set to false.
Once it's loaded up, select the combobox and then attempt to deselect it
by
selecting the checkbox. This is rendered impossible by the combobox
retaining the focus, you cannot even close the form, such is it's grasp on
the focus.

I have found three ways of fixing this problem.

a) Remove the binding to Bar (a bit obvious)
b) Remove the binding to DateTime
c) Make the DateTimePicker visible !?!

I'm currently running Win2k. And .NET 2.00, I think 1.1 has the same
problem.
Code is below.

// SEARCH TAGS: Combobox Focus Bug Binding Datetimepicker.Value
DateTimePicker.Visible

// CODE BEGINS

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication6
{
public class Bar
{
public Bar()
{
}
}

public class Foo
{
private Bar m_Bar = new Bar();
private DateTime m_DateTime = DateTime.Now;

public Foo()
{
}

public Bar Bar
{
get
{
return m_Bar;
}
set
{
m_Bar = value;
}
}

public DateTime DateTime
{
get
{
return m_DateTime;
}
set
{
m_DateTime = value;
}
}
}

public class TestBugControl : UserControl
{
public TestBugControl()
{
InitializeComponent();
}

public void InitializeData(IList types)
{
this.cBoxType.DataSource = types;
}

public void BindFoo(Foo foo)
{
this.cBoxType.DataBindings.Add("SelectedItem", foo, "Bar");
this.dtStart.DataBindings.Add("Value", foo, "DateTime");
}

/// <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 Component 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.checkBox1 = new System.Windows.Forms.CheckBox();
this.cBoxType = new System.Windows.Forms.ComboBox();
this.dtStart = new System.Windows.Forms.DateTimePicker();
this.SuspendLayout();
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(14, 5);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(97, 20);
this.checkBox1.TabIndex = 0;
this.checkBox1.Text = "checkBox1";
this.checkBox1.UseVisualStyleBackColor = true;
//
// cBoxType
//
this.cBoxType.FormattingEnabled = true;
this.cBoxType.Location = new System.Drawing.Point(117, 3);
this.cBoxType.Name = "cBoxType";
this.cBoxType.Size = new System.Drawing.Size(165, 24);
this.cBoxType.TabIndex = 1;
//
// dtStart
//
this.dtStart.Location = new System.Drawing.Point(117, 40);
this.dtStart.Name = "dtStart";
this.dtStart.Size = new System.Drawing.Size(165, 23);
this.dtStart.TabIndex = 2;
this.dtStart.Visible = false;
//
// TestBugControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.dtStart);
this.Controls.Add(this.cBoxType);
this.Controls.Add(this.checkBox1);
this.Font = new System.Drawing.Font("Verdana", 9.75F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
((byte)(0)));
this.Margin = new System.Windows.Forms.Padding(4);
this.Name = "TestBugControl";
this.Size = new System.Drawing.Size(285, 66);
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.ComboBox cBoxType;
private System.Windows.Forms.DateTimePicker dtStart;
}

public class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Load += new EventHandler(Form1_Load);
}

void Form1_Load(object sender, EventArgs e)
{
InitializeControl();
}

public void InitializeControl()
{
TestBugControl control = new TestBugControl();
IList list = new ArrayList();
for (int i = 0; i < 10; i++)
{
list.Add(new Bar());
}
control.InitializeData(list);
control.BindFoo(new Foo());
this.Controls.Add(control);
}

/// <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();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Text = "Form1";
}

#endregion
}

static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new Form1());
}
}
}


Mar 13 '07 #2

P: n/a
Thanks for looking into it VJ. :D It's certainly an interesting one, eh?
Could you post the modifications you made to the code so I can reproduce
your workaround on this side?

I guess M$ could solve the problem but i'm pretty sure someone else must
stumbled across this at some point and researched it as well, has this
already been reported as a bug in the framework or am I bypassing a binding
standard and just writing bad code?
From what I can make out the example is pretty standard, isn't it?

King Regards

Simon

"VJ" <no***********@yahoo.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
I tried adding your user control add design time, and then assigning
values
at load it worked, without any of your workaround.. Create, add the
control
to form and then assign values to it. That order also works. Some how
creating, assigning and adding to Form fails.. Interesting situation, I
will
see if I can find time later to work this. Let me know if you learn
anything
new..

Bottom of problem, maybe Microsoft can answer?..

VJ

"Simon Tamman" <i_**********************************@NOSPAMhotmai l.com>
wrote in message news:st*************@newsfe4-gui.ntli.net...
I've come across an interesting bug.
I have workarounds but i'd like to know the root of the problem. I've
stripped it down into a short file and hope someone might have an idea
about
what's going on.

It's a simple program that loads a control onto a form and binds "Foo"
against a combobox ("SelectedItem") for it's "Bar" property and a
datetimepicker ("Value") for it's "DateTime" property. The
DateTimePicker.Visible value is set to false.
Once it's loaded up, select the combobox and then attempt to deselect it
by
selecting the checkbox. This is rendered impossible by the combobox
retaining the focus, you cannot even close the form, such is it's grasp
on
the focus.

I have found three ways of fixing this problem.

a) Remove the binding to Bar (a bit obvious)
b) Remove the binding to DateTime
c) Make the DateTimePicker visible !?!

I'm currently running Win2k. And .NET 2.00, I think 1.1 has the same
problem.
Code is below.

// SEARCH TAGS: Combobox Focus Bug Binding Datetimepicker.Value
DateTimePicker.Visible

// CODE BEGINS

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication6
{
public class Bar
{
public Bar()
{
}
}

public class Foo
{
private Bar m_Bar = new Bar();
private DateTime m_DateTime = DateTime.Now;

public Foo()
{
}

public Bar Bar
{
get
{
return m_Bar;
}
set
{
m_Bar = value;
}
}

public DateTime DateTime
{
get
{
return m_DateTime;
}
set
{
m_DateTime = value;
}
}
}

public class TestBugControl : UserControl
{
public TestBugControl()
{
InitializeComponent();
}

public void InitializeData(IList types)
{
this.cBoxType.DataSource = types;
}

public void BindFoo(Foo foo)
{
this.cBoxType.DataBindings.Add("SelectedItem", foo, "Bar");
this.dtStart.DataBindings.Add("Value", foo, "DateTime");
}

/// <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 Component 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.checkBox1 = new System.Windows.Forms.CheckBox();
this.cBoxType = new System.Windows.Forms.ComboBox();
this.dtStart = new System.Windows.Forms.DateTimePicker();
this.SuspendLayout();
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(14, 5);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(97, 20);
this.checkBox1.TabIndex = 0;
this.checkBox1.Text = "checkBox1";
this.checkBox1.UseVisualStyleBackColor = true;
//
// cBoxType
//
this.cBoxType.FormattingEnabled = true;
this.cBoxType.Location = new System.Drawing.Point(117, 3);
this.cBoxType.Name = "cBoxType";
this.cBoxType.Size = new System.Drawing.Size(165, 24);
this.cBoxType.TabIndex = 1;
//
// dtStart
//
this.dtStart.Location = new System.Drawing.Point(117, 40);
this.dtStart.Name = "dtStart";
this.dtStart.Size = new System.Drawing.Size(165, 23);
this.dtStart.TabIndex = 2;
this.dtStart.Visible = false;
//
// TestBugControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.dtStart);
this.Controls.Add(this.cBoxType);
this.Controls.Add(this.checkBox1);
this.Font = new System.Drawing.Font("Verdana", 9.75F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
((byte)(0)));
this.Margin = new System.Windows.Forms.Padding(4);
this.Name = "TestBugControl";
this.Size = new System.Drawing.Size(285, 66);
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.ComboBox cBoxType;
private System.Windows.Forms.DateTimePicker dtStart;
}

public class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Load += new EventHandler(Form1_Load);
}

void Form1_Load(object sender, EventArgs e)
{
InitializeControl();
}

public void InitializeControl()
{
TestBugControl control = new TestBugControl();
IList list = new ArrayList();
for (int i = 0; i < 10; i++)
{
list.Add(new Bar());
}
control.InitializeData(list);
control.BindFoo(new Foo());
this.Controls.Add(control);
}

/// <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();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Text = "Form1";
}

#endregion
}

static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new Form1());
}
}
}


Mar 13 '07 #3

P: n/a
That's great, thanks to your changes I was able remove the bug from my main
source code. :D

The order of adding the control to the form before performing the binding
seems to be key.
The values of the controls don't need to be set first and UserControl seems
to be blameless in this occurance.
It may be something to do with the main BindingContext changing perhaps?
(e.g. you bind when the control isn't on the form and then you add the
control to the form) I'm not 100% sure, but thanks for your help
nevertheless.
"VJ" <no***********@yahoo.comwrote in message
news:O9**************@TK2MSFTNGP03.phx.gbl...
yea its very interesting. I have not used binding that much, theory looks
right to me and maps to what I have learned, but as always the
implementation differs a little. so may be so one implemented could
provide
a insight. I have attached a zip file with what I changed, I tried quite a
few.

Binding is very straight forward concept.. I still suspect the UserControl
base class, that is weird. We avoid it at the max. Most we do is use a
control and inherit from there, and use panels if we need multiple
controls
inside..

I did not see this as a bug in Framework. maybe its a hidden feature :-)
just kidding.

VJ

"Simon Tamman" <i_**********************************@NOSPAMhotmai l.com>
wrote in message news:7A**************@newsfe3-gui.ntli.net...
Thanks for looking into it VJ. :D It's certainly an interesting one, eh?
Could you post the modifications you made to the code so I can reproduce
your workaround on this side?

I guess M$ could solve the problem but i'm pretty sure someone else must
stumbled across this at some point and researched it as well, has this
already been reported as a bug in the framework or am I bypassing a
binding
standard and just writing bad code?
From what I can make out the example is pretty standard, isn't it?

King Regards

Simon

"VJ" <no***********@yahoo.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
I tried adding your user control add design time, and then assigning
values
at load it worked, without any of your workaround.. Create, add the
control
to form and then assign values to it. That order also works. Some how
creating, assigning and adding to Form fails.. Interesting situation, I
will
see if I can find time later to work this. Let me know if you learn
anything
new..

Bottom of problem, maybe Microsoft can answer?..

VJ

"Simon Tamman" <i_**********************************@NOSPAMhotmai l.com>
wrote in message news:st*************@newsfe4-gui.ntli.net...
I've come across an interesting bug.
I have workarounds but i'd like to know the root of the problem. I've
stripped it down into a short file and hope someone might have an
idea
about
what's going on.

It's a simple program that loads a control onto a form and binds
"Foo"
against a combobox ("SelectedItem") for it's "Bar" property and a
datetimepicker ("Value") for it's "DateTime" property. The
DateTimePicker.Visible value is set to false.
Once it's loaded up, select the combobox and then attempt to deselect
it
by
selecting the checkbox. This is rendered impossible by the combobox
retaining the focus, you cannot even close the form, such is it's
grasp
on
the focus.

I have found three ways of fixing this problem.

a) Remove the binding to Bar (a bit obvious)
b) Remove the binding to DateTime
c) Make the DateTimePicker visible !?!

I'm currently running Win2k. And .NET 2.00, I think 1.1 has the same
problem.
Code is below.

// SEARCH TAGS: Combobox Focus Bug Binding Datetimepicker.Value
DateTimePicker.Visible

// CODE BEGINS

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication6
{
public class Bar
{
public Bar()
{
}
}

public class Foo
{
private Bar m_Bar = new Bar();
private DateTime m_DateTime = DateTime.Now;

public Foo()
{
}

public Bar Bar
{
get
{
return m_Bar;
}
set
{
m_Bar = value;
}
}

public DateTime DateTime
{
get
{
return m_DateTime;
}
set
{
m_DateTime = value;
}
}
}

public class TestBugControl : UserControl
{
public TestBugControl()
{
InitializeComponent();
}

public void InitializeData(IList types)
{
this.cBoxType.DataSource = types;
}

public void BindFoo(Foo foo)
{
this.cBoxType.DataBindings.Add("SelectedItem", foo, "Bar");
this.dtStart.DataBindings.Add("Value", foo, "DateTime");
}

/// <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 Component 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.checkBox1 = new System.Windows.Forms.CheckBox();
this.cBoxType = new System.Windows.Forms.ComboBox();
this.dtStart = new System.Windows.Forms.DateTimePicker();
this.SuspendLayout();
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(14, 5);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(97, 20);
this.checkBox1.TabIndex = 0;
this.checkBox1.Text = "checkBox1";
this.checkBox1.UseVisualStyleBackColor = true;
//
// cBoxType
//
this.cBoxType.FormattingEnabled = true;
this.cBoxType.Location = new System.Drawing.Point(117, 3);
this.cBoxType.Name = "cBoxType";
this.cBoxType.Size = new System.Drawing.Size(165, 24);
this.cBoxType.TabIndex = 1;
//
// dtStart
//
this.dtStart.Location = new System.Drawing.Point(117, 40);
this.dtStart.Name = "dtStart";
this.dtStart.Size = new System.Drawing.Size(165, 23);
this.dtStart.TabIndex = 2;
this.dtStart.Visible = false;
//
// TestBugControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.dtStart);
this.Controls.Add(this.cBoxType);
this.Controls.Add(this.checkBox1);
this.Font = new System.Drawing.Font("Verdana", 9.75F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
((byte)(0)));
this.Margin = new System.Windows.Forms.Padding(4);
this.Name = "TestBugControl";
this.Size = new System.Drawing.Size(285, 66);
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.ComboBox cBoxType;
private System.Windows.Forms.DateTimePicker dtStart;
}

public class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Load += new EventHandler(Form1_Load);
}

void Form1_Load(object sender, EventArgs e)
{
InitializeControl();
}

public void InitializeControl()
{
TestBugControl control = new TestBugControl();
IList list = new ArrayList();
for (int i = 0; i < 10; i++)
{
list.Add(new Bar());
}
control.InitializeData(list);
control.BindFoo(new Foo());
this.Controls.Add(control);
}

/// <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();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Text = "Form1";
}

#endregion
}

static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new Form1());
}
}
}






Mar 15 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.