Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have added a dgvcomboboxcol to an existing dgv. The dgvcomboboxcol will replace an existing column and allow for user selection.

The code adds a list of items a user can select from, but I'd like to set the dgvcomboboxcol with a default the same as the column it replaced. The code below is copied from another question and compiles, but gives an error "dgvcomboboxcell value is not valid".

Thanks for any help.

What I have tried:

C#
public void BOOK_COMBO2()
        {

            DataGridViewComboBoxCell cb_cell = new DataGridViewComboBoxCell();
            DataGridViewComboBoxColumn cb_col = new DataGridViewComboBoxColumn();

            // Contract field
            cb_col.Items.AddRange("AP-21-Apr-16", "HSI-28-Apr-16", "");
            cb_col.FlatStyle = FlatStyle.Flat;
            cb_col.HeaderText = "newCONTRACT";
            cb_col.Width = 50;
            cb_col.ValueType = typeof(string);

            grdBOOK.Columns.Insert(5, cb_col);

            foreach (DataGridViewRow item in grdBOOK.Rows)
            {
                item.Cells[5].Value = (string)item.Cells[3].Value;      
            }

        }
Posted
Updated 15-Apr-16 1:41am
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900