AutoComplete dành cho DataGridView và ComboBox bình thường trong C#

* Lệnh cần để thể hiện ComboBox và DropDown dành cho DataGridView 

private void dgv_list_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (e.Control is DataGridViewComboBoxEditingControl)
{
((ComboBox)e.Control).DropDownStyle = ComboBoxStyle.DropDown;
((ComboBox)e.Control).AutoCompleteSource = AutoCompleteSource.ListItems;
((ComboBox)e.Control).AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
}
}

* Lệnh dành cho ComboBox bình thường (Tool Box) 

partial class lkClass
{
public String LKDisplay
{
get
{
return String.Format(“{0} – {1}”, this.Ma, this.Ten);
}
}
}

 

* Đoạn code để giúp Combobox có thể auto complete được:

 

lkComboBox.DataSource = lkList;
lkComboBox.ValueMember = “Ma”;
lkComboBox.DisplayMember = “LKDisplay”;

lkComboBox.AutoCompleteMode = AutoCompleteMode.Suggest;

 

lkComboBox.AutoCompleteSource = AutoCompleteSource.ListItems;

Tagged: , , , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: