如何在DataGridView中乘以列的值并将其显示为另一列 [英] how to multiply the value of column in DataGridView and show it another column

查看:350
本文介绍了如何在DataGridView中乘以列的值并将其显示为另一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是CSharp的新手....



我想将两列的值相乘并显示另一列。

我把代码编写为..

  int  s = Convert.ToInt32(dataGridView1.Rows [  0 ]。单元格[ 0 ]。值); 
int s1 = Convert.ToInt32(dataGridView1.Rows [ 0 ]。单元格[ 1 ]值);
int s13 = s1 * s;
dataGridView1.Rows [ 0 ]。单元格[ 2 ]。值= s13;





这个代码在一行中工作。我想做多行可能是5/6。



之后我想将datagridView的值保存在表格中。



Plz帮助我..



谢谢你的推荐

解决方案

< blockquote>搞定了。您应该使用CurrentRow而不是Rows [0]属性。应该没问题。



  int  s = Convert.ToInt32( dataGridView1.CurrentRow.Cells [ 0 ]。Value); 
int s1 = Convert.ToInt32(dataGridView1.CurrentRow.Cells [ 1 ]。Value) ;
int s13 = s1 * s;
dataGridView1.CurrentRow.Cells [ 2 ]。值= s13;


你好,



为什么要从代码隐藏中执行此代码,而是可以使用SQL查询来乘以值并在第三列中显示它。







 产品中选择 productID,productPrize,productSellCount,productPrize * productSellCount ; 





希望这能解决你的问题。



谢谢

-Amit。


int A = Convert.ToInt32(dataGridView1.CurrentRow.Cells [0] .Value);

int B = Convert.ToInt32(dataGridView1.CurrentRow.Cells [1] .Value);

int C = A * B;

dataGridView1.CurrentRow.Cells [2] .Value = C;


I am new in CSharp....

I want to multiply the value of two column and display it another column.
I have written the code as..

int s = Convert.ToInt32(dataGridView1.Rows[0].Cells[0].Value);
            int s1 = Convert.ToInt32(dataGridView1.Rows[0].Cells[1].Value);
            int s13 = s1 * s;
dataGridView1.Rows[0].Cells[2].Value = s13;



bt this code work in one row. I want to do more than one row may be 5/6.

And after that I want to save the value of datagridView in a table.

Plz help me..

Thanks in advans

解决方案

Got it. Instead of Rows[0] attribute, you should use CurrentRow. It should be fine.

int s = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value);
            int s1 = Convert.ToInt32(dataGridView1.CurrentRow.Cells[1].Value);
            int s13 = s1 * s;
dataGridView1.CurrentRow.Cells[2].Value = s13;


Hi,

Why you are doing this code from codebehind, instead you can use your SQL query to multiply value and display it in your third column.

like

select productID,productPrize,productSellCount, productPrize*productSellCount from products;



hope this will solve your problem.

Thanks
-Amit.


int A = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value);
int B = Convert.ToInt32(dataGridView1.CurrentRow.Cells[1].Value);
int C = A * B;
dataGridView1.CurrentRow.Cells[2].Value = C;


这篇关于如何在DataGridView中乘以列的值并将其显示为另一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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