这是我将数据输入网格的方式:
this.dataGridView1.Rows.Add("Room: " + label40.Text, "$" + label38.Text, type, textBox1.Text + "m", textBox2.Text + "m", label10.Text, label9.Text);
这就是我的尝试。循环:
private void button1_Click(object sender, EventArgs e)
{ 列出成本=新列表();
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (null != row && null != row.Cells[1].Value)
{
costs.Add(Convert.ToInt32(row.Cells[1].ToString()));
}
}
答案 0 :(得分:0)
试试这个,
private void button1_Click(object sender, EventArgs e)
{
List<int> costs = new List<int>();
//Iterate through each row in the grid
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (null != row && null != row.Cells[1].Value)
{
//Add cost value to list
costs.Add(Convert.ToInt32(row.Cells[1].Value.ToString()));
}
}
//get 50% of min value(lowest)
int result = costs.Min() / 2;
}