المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : How to use Combo box in C#



C# Programming
05-16-2009, 11:30 AM
Hi All,
I have a class Class1. In Class1 constructor I am calling InitializeComponent().Which will be used to add controls to form at runtime. I have one more method Initialize(). In this Initialize() I am filling the value for the combo box.
My problem is the value is not updated in combo box.

Could any one help me to solve this issue.

Code snippet:

Public Class1()
{
InitializeComponent();
}
Public void Intialize()
{
string[] employees = new string[]{"Hamilton, David", "Hensien, Kari"};
SampleComboBox.Items.AddRange(employee);
SampleComboBox.SelectedItem=employee[0];
SampleComboBox.SelectedIndexChanged += new System.EventHandler(this.SampleComboBox_SelectedIndexChanged);
}

This code is present in Designer.cs

Private InitializeComponent()
{
this.SampleComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.SampleComboBox.DropDownWidth = 97;
this.SampleComboBox.FormattingEnabled = true;
this.SampleComboBox.******** = new System.Drawing.Point(84, 16);
this.SampleComboBox.Name = "SampleComboBox";
this.SampleComboBox.Size = new System.Drawing.Size(91, 21);
this.SampleComboBox.TabIndex = 2;

this.Controls.Add(this.SampleComboBox);
this.Name = "SampleApp";
this.Size = new System.Drawing.Size(190, 51);
this.ResumeLayout(false);
}
private System.Windows.Forms.ComboBox SampleComboBox;



Thanks,
Anandi