I am creating a Desktop Application and I have a grid named custCartGrid on my form. I want to select Transaction type like Sale or Return through combo-box in row in Grid. I am new to combo-boxes in Grid so I have not much idea that why I am not getting the required results.Here is the code that I have applied to get combo-box.
DataGridViewComboBoxColumn dcom = new DataGridViewComboBoxColumn();
dcom.HeaderText = "Combobox";
dcom.Items.Add("Sale");
dcom.Items.Add("Return");
custCartGrid.Columns.Add(dcom);
- When I am inserting second row, it adds another combo-box in first row like I have 2 combo-boxes in first row and then it creates second row with two combo-boxes. Like wise for third row.
- I am not getting items in combo-box that I have added through
items.add
method.
Please help me in this..
this is the complete code that i used for inserting values in grid
DateTime dt = DateTime.Now;
string date = dt.ToShortDateString();
//date
// determineTransactionType();
custCartGrid.Rows.Add();
GridRow = custCartGrid.Rows.Count - 1;
custCartGrid["CODE", GridRow].Value = productDetails.Tables[0].Rows[0]["ProductID"].ToString();
custCartGrid["Name", GridRow].Value = productDetails.Tables[0].Rows[0]["ProductName"].ToString();
custCartGrid["PRICE", GridRow].Value = tb_FP_Price_Single_Product.Text.Trim();
custCartGrid["CATEGORY", GridRow].Value = productDetails.Tables[0].Rows[0]["CatName"].ToString();
custCartGrid["MODE", GridRow].Value = "Sale";
DataGridViewComboBoxColumn dcom = new DataGridViewComboBoxColumn();
dcom.HeaderText = "Combobox";
dcom.Items.Add("Sale");
dcom.Items.Add("Return");
custCartGrid.Columns.Add(dcom);