Thursday, August 27, 2009

Windows Programming - Working with ComboBox

using System;
using System.Windows.Forms;
using System.Drawing;
class myfrm : Form
{
ListBox c;
Button b;
public myfrm()
{
c = new ListBox();
c.SetBounds(100, 100, 100, 50);
c.Items.Add("aaa");
c.Items.Add("bbb");
c.Items.Add("ccc");

c.SelectionMode = SelectionMode.MultiSimple;

/* other Selection Modes
SelectionMode.MultiExtended
SelectionMode.MultiSimple
SelectionMode.None
SelectionMode.One
*/
this.Controls.Add(c);

b = new Button();
b.Text = "Ok";
b.SetBounds(100, 300, 100, 50);
this.Controls.Add(b);
b.Click +=new EventHandler(fun);

}
void fun(object o, EventArgs e)
{
//MessageBox.Show(c.Text);
//c.Items.Clear();
//c.Items.Count

//c.Items.Remove("aaa");
//c.Items.RemoveAt(0);

foreach (string x in c.SelectedItems)
{
MessageBox.Show(x);
}
}

}
class Program
{
static void Main(string[] args)
{
myfrm f = new myfrm();
f.ShowDialog();
}
}

No comments:

Post a Comment