Change text color of a listbox item

  1. Change DrawMode = OwnerDrawFixed

private void listBox1_DrawItem(object sender, DrawItemEventArgs e) {

e.DrawBackground();

e.Graphics.DrawString(listBox1.Items[e.Index].ToString(), listBox1.Font, Brushes.Green, e.Bounds);

}

Anuncios

Add combo box item from ListBox

List<string> CCode = new List<string>();

CylinderCOdeComboBox.DataSource = null;

CCode.Add(“item1”);

CylinderCodeComboBox.DataSource = CCode;

Get text of selected items in a listbox

foreach(var item in listBox1.SelectedItems){

MessageBox.Show(item.ToString());

}