Click here to Skip to main content
15,867,969 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi guys,

I am using a DatagridView in which i have made one column as Dropdown type (as we can set from properties of DGV. I am binding DGV with a table.

I have set DataPropertyName of DGV as column name from DB.
Now when i am binding it is giving exception.

"DATAGRIDVIEW COMBOBOXCELL VALUE is not valid..."

On cell click i am able to bind the combobox. But on load of gridview please how i handle this exception.


My code :
OdbcCommand cmd = new OdbcCommand("select * from work_tot_incident_effort_test", conn);
                da = new OdbcDataAdapter(cmd);
                ds = new DataTable();
                da.Fill(ds);

                conn.Close();
                if (ds.Rows.Count > 0)
                {
                    gvDetails.AutoGenerateColumns = false;
                    gvDetails.DataSource = ds.DefaultView;

                    this.gvDetails.Columns["ROW_ID"].Visible = false;
                    this.gvDetails.Columns["PAR_ROW_ID"].Visible = false;
                    //gvDetails.DataBind();
                }

//Here i am binding DGV.

on cell click i am again binding Dropdown inside DGV.
if (e.ColumnIndex == 2)
               {
                   DataGridViewComboBoxCell ComboColumn = (DataGridViewComboBoxCell)(gvDetails.Rows[e.RowIndex].Cells[2]);

                   ComboColumn.DataSource = ds;
                   ComboColumn.DisplayMember = "EMP_ID";
               }

Thanks for your help.
Posted
Updated 4-Oct-13 6:03am
v2
Comments
joshrduncan2012 4-Oct-13 13:21pm    
What line is the error pointing to?

Hello ,

suppose you have one datagridview and their are two columns . one of them is combobox named as
cmbproduct and other is textbox named as txtother. and if you want to bind the combobox value from dataset then
cmbproduct.DataSource = dsproduct.Tables[0].Columns[0].Table.DefaultView;
cmbproduct.ValueMember = "PId";
cmbproduct.DisplayMember = "Pname";


put this code in window_load or other event .

thanks
Animesh
 
Share this answer
 
Comments
Kishan_1991 5-Oct-13 1:55am    
--- use this
DataGridViewComboBoxColumn cell1 =
(DataGridViewComboBoxColumn)(dgvRef.Columns["Column name"]);
cell1.DataSource = ds;
cell1.DisplayMember = "EmpID";

and put this code in to initializecomponent......



Thanks
Kishan P
raviendra 6-Aug-16 17:01pm    
no work code
DataGridViewComboBoxColumn cell1 =
(DataGridViewComboBoxColumn)(dgvRef.Columns["Column name"]);
cell1.DataSource = ds;
cell1.DisplayMember = "EmpID";
 
Share this answer
 

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