datagridview 乘法

来源:百度知道 编辑:UC知道 时间:2024/05/10 10:56:19
datagridview里“数量”列的值,跟“单价”列的值,相乘以后,等于“金额”列的值,当数量跟单价输入完毕,离开单元格后,自动算出金额,这段代码应该怎么写啊,哪位高手能帮帮我,谢谢啦!!!

先添加一个datagridview,再把你说的那三列加上,最后加上下面的代码就行了
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
try
{
if (dataGridView1[0, e.RowIndex].Value != null && dataGridView1[1, e.RowIndex].Value != null)
{
dataGridView1[02, e.RowIndex].Value =
Convert.ToUInt32(dataGridView1[0, e.RowIndex].Value) * Convert.ToUInt32(dataGridView1[1, e.RowIndex].Value);
}
}
catch (Exception)
{
}
}