Hi All.
I have a problem with combobox, what I want is when combobox gets focus I need it to show the dropdown list
t.This is fine if the user selects the combobox via keystrokes but when the combobox is selected via mouse click it draws
the dropdown list twice. As I am trapping the enter event, I can see thats is called as well some other ?
the style is set to dropdownlist as they must select one from the list
I assume I must trap a mouse event so it doesn't draw the dropdown list because I will be in the enter event, but which one?
thanks for any input.
Code below.
P.S I did post this question to m.p.d.f.winforms but did not receive any replies.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace test
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <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.cbp = new System.Windows.Forms.ComboBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// cbp
//
this.cbp.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbp.Location = new System.Drawing.Point(208, 176);
this.cbp.Name = "cbp";
this.cbp.Size = new System.Drawing.Size(121, 21);
this.cbp.TabIndex = 6;
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(208, 136);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 1;
this.textBox1.Text = " ";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(792, 566);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.cbp);
this.Name = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.ComboBox cbp;
private void Form1_Load(object sender, System.EventArgs e)
{
cbp.Items.Add("Hello");
cbp.Items.Add("Everyone");
cbp.DropDown+=new EventHandler(cbp_DropDown);
cbp.Enter+=new EventHandler(cbp_Enter);
cbp.MouseUp+=new MouseEventHandler(cbp_MouseUp);
}
private void cbp_DropDown(object sender, EventArgs e)
{
if (cbp.DroppedDown==true)
return;
}
private void cbp_Enter(object sender, EventArgs e)
{
cbp.DroppedDown=true;
}
private void cbp_MouseUp(object sender, MouseEventArgs e)
{
cbp.DroppedDown=true;
}
}
}