void Timeout() { conn = new SqlConnection(connec.GetServer()); conn.Open(); string q = "select Distinct TimeOUT from tblTime Where Temp= '" +"f"+ "'"; SqlDataAdapter da = new SqlDataAdapter(q, conn); DataTable dt = new DataTable(); da.Fill(dt); //Craete combo column DataGridViewComboBoxColumn combo2 = new DataGridViewComboBoxColumn(); //Assing dataSource combo2.DataSource = dt; //Assing table Field on combo combo2.DisplayMember = "TimeOUT"; combo2.ValueMember = "TimeOUT"; combo2.HeaderText = "TimeOUT"; //Adding combo box column in dataGridView dataGridView1.Columns.Insert(2, combo2); // 0 is the number of array to the field found in the database. dataGridView1.Refresh(); }
System.Windows.Forms
DataGridViewComboBoxCell cell = // some cell int comboBoxListItemIndex = // some index // ... cell.Items.RemoveAt(comboBoxListItemIndex); // ... cell.Items.Insert(comboBoxListItemIndex, "some item"); // ... // Or you can preserve some item before deleting by copying the reference // somewhere and later insert it again: object saveItem = cell.Items[comboBoxListItemIndex]; // or it could be some class's field // ... cell.Items.Insert(comboBoxListItemIndex, saveItem);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)