Dear all,
I see a very weird behavior in my C# .NET project. When I bind my
custom DataComboBox control, all event handlers stop working! Does
anyone have any idea how to fix that?
Thanks in advance!
Best regards,
Nikolay
---
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using SySal.OperaDb;
namespace BatchLinkConfigurator
{
/// <summary>
/// Summary description for Selector.
/// </summary>
public class Selector : System.Windows.Forms.Form
{
public static void Main()
{
Selector theSelector = new Selector();
theSelector.ShowDialog();
}
private long _configId;
private class Config
{
private long _id;
public long Id
{
get{return _id;}
set{_id = value;}
}
}
private Config _config = new Config();
private OperaDbConnection _connection;
private DataComboBox.DataComboBox dataComboBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Selector()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
OperaDbCredentials cred = OperaDbCredentials.CreateFromRecord();
_connection = cred.Connect();
_connection.Open();
dataComboBox1.Fill("SELECT ID, DESCRIPTION FROM TB_PROGRAMSETTINGS
WHERE EXECUTABLE='IntercalibrationDriver.exe'", _connection);
dataComboBox1.DataBindings.Add("SelectedValue", _config, "Id");
}
/// <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.dataComboBox1 = new DataComboBox.DataComboBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// dataComboBox1
//
this.dataComboBox1.Location = new System.Drawing.Point(16, 16);
this.dataComboBox1.Name = "dataComboBox1";
this.dataComboBox1.Size = new System.Drawing.Size(264, 21);
this.dataComboBox1.TabIndex = 0;
this.dataComboBox1.Text = "dataComboBox1";
//
// button1
//
this.button1.Location = new System.Drawing.Point(16, 232);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "Edit";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(200, 232);
this.button2.Name = "button2";
this.button2.TabIndex = 2;
this.button2.Text = "Cancel";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Selector
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.dataComboBox1);
this.Name = "Selector";
this.Text = "Selector";
this.ResumeLayout(false);
}
#endregion
private void button2_Click(object sender, System.EventArgs e)
{
Close();
}
private void button1_Click(object sender, System.EventArgs e)
{
MessageBox.Show("Preved!");
//MessageBox.Show("Id = " + _config.Id);
}
}
}