Click here to Skip to main content
15,924,367 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i write this code :-
C#
void FillComboboxCarPlace()
        {
            try
            {
                dSet = new DataSet();
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }
                s = "select Move_id , Move_Place from Car_Move_Place";
                sCommand = new SqlCommand(s, con);
                sdAdapter = new SqlDataAdapter();
                sdAdapter.SelectCommand = sCommand;
                sdAdapter.Fill(dSet);
                DataRow dr = dSet.Tables[0].NewRow();
                dr.ItemArray = new object[2] { 0, " ---Select--- " };
                dSet.Tables[0].Rows.InsertAt(dr, 0);
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    //DataGridViewComboBoxCell ContactCombo = (DataGridViewComboBoxCell)(row.Cells["Car_Move_Place"]);
                    ComboMovePlace.ValueMember = "Move_id";
                    ComboMovePlace.DisplayMember = "Move_Place";
                    ComboMovePlace.DataSource = dSet.Tables[0];
                }
                //ComboMovePlace.ValueMember = "Move_id";
                //ComboMovePlace.DisplayMember = "Move_Place";
                //ComboMovePlace.DataSource = dSet.Tables[0];
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }

            }
            catch
            {
                return;
            }
        }


What I have tried:

i try write this code but it's uncorrect
Posted
Updated 23-Jun-16 2:49am

1 solution

try this
C#
int index = 0; // index of the combox box column ( zero based index )
           foreach (DataGridViewRow row in dataGridView1.Rows)
           {
               var cbxMove = row.Cells[index] as DataGridViewComboBoxCell;
               cbxMove.ValueMember = "Move_id";
               cbxMove.DisplayMember = "Move_Place";
               cbxMove.DataSource = dSet.Tables[0];
           }
 
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