how to allow user manual entry in datagridview combobox in c# -
i trying enter values in datagridview combobox. not allows. do?
private void gridstockitementry_editingcontrolshowing(object sender, datagridvieweditingcontrolshowingeventargs e) { datagridviewrow row = gridstockitementry.currentrow; datagridviewcell cell = gridstockitementry.currentcell; if (e.control.gettype() == typeof(datagridviewcomboboxeditingcontrol)) { if (cell == row.cells["itemname"] && convert.tostring(row.cells["type"].value) == "raw material") { datagridviewcomboboxeditingcontrol cbo = e.control datagridviewcomboboxeditingcontrol; cbo.dropdownstyle = comboboxstyle.dropdown; cbo.validating += new canceleventhandler(cbo_validating); } } } void cbo_validating(object sender, canceleventargs e) { datagridviewcomboboxeditingcontrol cbo = sender datagridviewcomboboxeditingcontrol; datagridview grid = cbo.editingcontroldatagridview; object value = cbo.text; // add value list if not there if (cbo.items.indexof(value) == -1) { datagridviewcomboboxcell cbocol = (datagridviewcomboboxcell)grid.currentcell; // must add both current combobox template, avoid duplicate entries... cbo.items.add(value); cbocol.items.add(value); grid.currentcell.value = value; } }
Comments
Post a Comment