Windows中的Gridview乘法 [英] Gridview Multiplication in windows

查看:107
本文介绍了Windows中的Gridview乘法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,



我创建了一个gridview。我想要乘以2列值。并显示在第3列。我如何给出一个代码请帮帮我..









问候,

Vino。

解决方案

使用查询将两列相乘并显示在第3列中

< pre lang =SQL> 选择 col1,col2,(col1 * col2) as col3 来自 table1


  / //   /为网格创建单元格值更改事件
/// / this.grd1.CellValueChanged + = tab tab
this .grd1.CellValueChanged + = < span class =code-keyword> new DataGridViewCellEventHandler(grd1_CellValueChanged);

/// /关于活动
/// ///////假设column0和column 1是你想要乘以
void grd1_CellValueChanged( object sender,DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0
{
grd1.Rows [e.RowIndex ] .Cells [ column2]。Value = Convert.ToString(Convert.ToDouble(grd1.Rows) [e.RowIndex] .Cells [ column0]。Value)* Convert.ToDouble(grd1。行[e.RowIndex] .Cells [ column1]。Value));
}
else if (e.ColumnIndex == 1
{
grd1.Rows [e.RowIndex] .Cells [ column2]。Value = Convert.ToString(Convert.ToDouble(grd1.Rows [e.RowIndex] .Cells [ column0]。Value)* Convert.ToDouble(grd1.Rows [e.RowIndex] .Cells [ column1]。Value));
}
}


Dear Frnds,

I have created one gridview. I want to Multiply 2 columns values. and display in 3rd column. how i give a code please help me..




With Regards,
Vino.

解决方案

use query to multiply two columns and show in 3rd column

select col1 ,col2,(col1*col2)as col3 from table1


////create cell value changed event for ur grid
//// this.grd1.CellValueChanged += tab tab
 this.grd1.CellValueChanged += new DataGridViewCellEventHandler(grd1_CellValueChanged);

////on the event
//////////assuming column0 and column 1 are the columns u want to multiply
void grd1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
  if (e.ColumnIndex == 0)
  {
        grd1.Rows[e.RowIndex].Cells["column2"].Value=Convert.ToString(Convert.ToDouble(grd1.Rows[e.RowIndex].Cells["column0"].Value)*Convert.ToDouble(grd1.Rows[e.RowIndex].Cells["column1"].Value));
   }
else  if (e.ColumnIndex == 1)
  {
        grd1.Rows[e.RowIndex].Cells["column2"].Value=Convert.ToString(Convert.ToDouble(grd1.Rows[e.RowIndex].Cells["column0"].Value)*Convert.ToDouble(grd1.Rows[e.RowIndex].Cells["column1"].Value));
   }
}


这篇关于Windows中的Gridview乘法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆