Click here to Skip to main content
15,891,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
only the last value added to combobox not all values , why??
Note : i adding rows programmatically to dgv
my code is :
C#
connection.Open();
            OleDbCommand cmd = new OleDbCommand();
            cmd.Connection = connection;
            string query = "select * from product_details";
            cmd.CommandText = query;
            OleDbDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {

                dataGridView1.ColumnCount = 2;

                dataGridView1.Columns[0].Name = "barcode";
                dataGridView1.Columns[1].Name = "product name ";
  

                dataGridView1.Rows.Add();

                DataGridViewComboBoxCell ComboBoxCell = new DataGridViewComboBoxCell();
                ComboBoxCell.Items.AddRange(new string[] {            (reader["barcode"].ToString()) });
                this.dataGridView1[0, 0] = ComboBoxCell;
                this.dataGridView1[0, 0].Value = (reader["barcode"].ToString());
}
connection.close();
}
Posted
Updated 20-Jan-15 3:51am
v3

Hello ,

suppose you have one datagridview and there one comboboxcolumn named as
cmbproduct 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 where you want to load the combobox .

thanks
Animesh
 
Share this answer
 
Comments
Peter M. Adeeb 24-Jan-15 11:38am    
thanks for response . it works thanks ,
but why when selecting an item from combo1 , combo2 dosen't show the value member ,
any ideas ??
Animesh Datta 25-Jan-15 5:44am    
Please go through this link
http://www.codeproject.com/Answers/683853/Using-DataGridViewComboBoxColumn-and-its-value-in?arn=0#answer1

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