【发布时间】:2016-03-21 04:35:10
【问题描述】:
我正在创建一个桌面应用程序,并且我的表单上有一个名为 custCartGrid 的网格。我想通过网格中行中的组合框选择交易类型,如销售或退货。 我是 Grid 中的组合框的新手,所以我不太清楚为什么我没有得到所需的结果。这是我用于获取组合框的代码。
DataGridViewComboBoxColumn dcom = new DataGridViewComboBoxColumn();
dcom.HeaderText = "Combobox";
dcom.Items.Add("Sale");
dcom.Items.Add("Return");
custCartGrid.Columns.Add(dcom);
- 当我插入第二行时,它会在第一行添加另一个组合框,就像我在第一行有 2 个组合框,然后它会创建第二个 有两个组合框的行。第三排也是如此。
- 我没有在通过
items.add方法添加的组合框中获取项目。
请帮帮我..
这是我用于在网格中插入值的完整代码
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);
【问题讨论】:
-
你改变datagridView的列数了吗?它在哪里被初始化?请发布整个代码。
-
我没有看到您的代码有任何问题,包括问题中的 custCartGrid 构造和事件。这可能会有所帮助。
-
@UsamaZafar 我对此不太了解,请您将我的代码更改为我的情况好吗?我想要组合框在我的行中
-
您发布的代码似乎没问题。在看到整个事情之前,我无法确定这个问题。发布用于构造“custCartGrid”的代码部分
-
@UsamaZafar 我已经编辑了这个问题。请检查一下
标签: c# datagridview combobox datagridviewcomboboxcell