Please try this sample code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
BindingList<string> course = new BindingList<string>() { "AFF", "PST", "Please add to new course" };
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
DropDownList1.DataSource = course;
DropDownList1.DisplayMember = "course";
DropDownList1.ValueMember = "course";
textBox1.Visible = false;
textBox1.Text = "Please add to new course";
}
private void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedItem.ToString() == "Please add to new course")
{
textBox1.Visible = true;
}
else
{
textBox1.Visible = false;
}
}
private void textBox1_Leave(object sender, EventArgs e)
{
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter && !course.Contains(textBox1.Text) && !string.IsNullOrEmpty(textBox1.Text))
{
course.Add(textBox1.Text);
DropDownList1.SelectedItem = textBox1.Text;
}
}
}
}