how to make datagridview combobox editable in c#
hello all,
i using c#.net create windows application, here use datagridview add new details , use combobox datagridview combobox coloum select items , want add new item here.
i aslo set datasoure for datagridview coloum bind data base,
i want edit datagridview combobox coloum, here color column want add new color cant , restrict enter number on column
here design
here code
add datagridview combobox coloum on load
datagridviewcomboboxcolumn cmb1 = new datagridviewcomboboxcolumn();
cmb1.headertext = "color";
gvvd.columns.add(cmb1);
{
datagridviewcomboboxeditingcontrol combocontrol = e.control datagridviewcomboboxeditingcontrol;
if (combocontrol != null)
{
//set dropdown style editable combobox
if (combocontrol.dropdownstyle != comboboxstyle.dropdown)
{
combocontrol.dropdownstyle = comboboxstyle.dropdown;
// int r = dgvform.currentrow.index;
}
}
}
private void gvvd_cellvalidating(object sender, datagridviewcellvalidatingeventargs e)
{
try
{
datagridviewcomboboxcell cell = gvvd.currentcell datagridviewcomboboxcell;
if (cell != null && !cell.items.contains(e.formattedvalue))
{
cell.items.insert(0, e.formattedvalue);
if (gvvd.iscurrentcelldirty)
{
gvvd.commitedit(datagridviewdataerrorcontexts.commit);
}
cell.value = cell.items[0];
}
}
catch
{
}
}
mahendra kumar verma
jdweng
Visual Studio Languages , .NET Framework > Visual C#
Comments
Post a Comment