作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
private void dgv_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
int MaxRows = dgv.Rows.Count;
for (int i = 0; i < MaxRows-1; i++)
{
SqlDataAdapter da = new SqlDataAdapter("SELECT CAST(originalPrice * " + (1.00 + (float.Parse(txtMarkUp.Text) / 100.00)).ToString() + " * " + (1.00 + (float.Parse(dgv.Rows[i].Cells[4].Value.ToString()) / 100.00)).ToString() + " AS decimal (8,2)) AS sellingPrice FROM Warehouse WHERE barcode = '" + Convert.ToString(dgv.Rows[i].Cells[2].Value) + "'", conn);
DataTable dt = new DataTable();
da.Fill(dt);
DataGridViewComboBoxColumn sellingPrice = dgv.Columns["sellingPrice"] as DataGridViewComboBoxColumn;
sellingPrice.DataSource = dt;
sellingPrice.ValueMember = "sellingPrice";
sellingPrice.DisplayMember = "sellingPrice";
dgv.Rows[i].Cells[5].Value = dt.Rows[0].ItemArray.GetValue(0);
dgv.Rows[i].Cells[4].Value = dt.Rows[0].ItemArray.GetValue(2).ToString(); //percent of tax for that category of product
}
}
此代码运行良好,但仅适用于组合框中的一个值...我需要组合框不同行中的不同值。我怎样才能做到这一点?例如,当第 2 列中的产品发生变化时,我需要它来更改第 5 列的值,这是带有销售价格的组合框。任何帮助将不胜感激,我几乎没有解决方案。谢谢。
最佳答案
假设您想为组合框列按行绑定(bind)不同的值,我不确定您想要什么在那种情况下,如果您可以明智地确定条件,请使用此
(dgv.Rows[i].Cells[5] as DataGridViewComboBoxCell).DataSource = dt;
(dgv.Rows[i].Cells[5] as DataGridViewComboBoxCell).ValueMember = "sellingPrice";
(dgv.Rows[i].Cells[5] as DataGridViewComboBoxCell).DisplayMember = "sellingPrice";
这将为该特定单元格而不是您当前正在执行的列设置数据源。
希望这对您有所帮助。
关于c# - DataGridView 中不同行的不同 ComboBox 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5855946/
在我的 android 应用程序中,我想在同一行中实现 2 个文本字段。如果文本太长可以转到下一行。所以我使用了更精简的水平布局并添加了 2 个文本字段。 [例如:TextView1、TextV
由于node使用了javascript,它可以充当webrtc peer吗? 然后我可以将它编码为 VP8 流并广播给所有其他对等方吗? 最佳答案 WebRTC 是一个浏览器 API 而不是 Java
我是一名优秀的程序员,十分优秀!