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);

private void gvvd_editingcontrolshowing(object sender, datagridvieweditingcontrolshowingeventargs e)
        {
            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

i not try use editable combobox.  have done in 1 of projects , difficult use.  wouldn't recommend editing text box in datagridview.  better bind comboxboxes , text boxes in dgv regular text boxes , comboboxes.  dgv designed view data , not edit data.  better make form 1 textboxes/comboboxes each column of dgv.  user selected row of dgv automatically fill individual textboxes/comboboxes.  have button when user modified textboxes/comboboxes dgv gets updated.

jdweng



Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

BizTalk Server 2013 Azure VM Log Shipping and HA for hosts

How to Share webservice object to all user