如何在datagridview中做到这一点? [英] how to make this in datagridview ?
本文介绍了如何在datagridview中做到这一点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好.
我的栏有数量,价格和commonPrice.我想用价格*数量值填充这个commonPrice.
Hello.
I have column there is quantity, price and commonPrice. i want to fill this commonPrice with price * quantity value.
How can i do this?
推荐答案
如果u在GridView单元格中输入值.
处理Datagridview1_CellValueChanged事件
If u are Entering Values in GridView Cells.
Handle Datagridview1_CellValueChanged Event
Exa:
private void dgrid_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if(e.RowIndex>=0)
{
if(!string.IsnullOrEmpty(dgrid.Rows[e.RowIndex].Cells["quantity"].Value.ToString()) && !string.IsnullOrEmpty(dgrid.Rows[e.RowIndex].Cells["Price"].Value.ToString())
{
dgrid.Rows[e.RowIndex].Cells["commonPrice"].Value = Convert.ToDouble(dgrid.Rows[e.RowIndex].Cells["quantity"].Value) *
Convert.ToDouble(dgrid.Rows[e.RowIndex].Cells["Price"].Value)
//Ensure That Quantity and Price Should be Digits Only.
}
}
}
vote if it is useful one.
莱斯特,
首先,将Price值输入到DataTable中,然后使用以下代码
dtData-> DataTable对象
Hi Lester,
First you get the Price value into DataTable and then to use the following Code
dtData --> DataTable Object
dtData.Columns.Add("CommonPrice");
for(int ix=0;ix<dtData.Rows.Count;ix++)
{
dtData.Rows[ix]["CommonPrice"]=((decimal.Parse(dtData.Rows[ix]["Price"]))*(int.Parse(TextBox1.Text))).ToString();
}
DataGridView1.DataSource=dtData.Copy();
试试这个代码.
干杯:)
Try this code.
Cheers :)
请澄清.
如果是,那么U将从表中获取数据
您已将此查询与gridview绑定.
如
从表名中选择数量,价格,数量*价格作为通用价格
Please clarify.
U would be fetching data from table if yes then
you u have bind this query with gridview.
as
select quantity,price ,quantity*price as commonPrice from tablename
这篇关于如何在datagridview中做到这一点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文