简体   繁体   中英

Editing Combobox item in Datagridview in C#

I have a Datagridview in Winform. One of the column is a Combobox . Is it possible to set the property such that user can enter apart from being able to select the entries from the dropdown list.

I was able to do it on a Combobox item with a following changes from the properties window:

AutoCompleteMode.SuggestAppend;
AutoCompleteSource.CustomSource;
DropDownStyle : Dropdown;

Thanks

Something like this may Help :-

private void DataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
    if (DataGridView1.CurrentCell.ColumnIndex == yourComboBoxColum)
    {
        ComboBox combo = e.Control as ComboBox;

        if (combo == null)
            return;

        combo.DropDownStyle = ComboBoxStyle.DropDown;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM