将文本框值与datagridview单元相乘 [英] Multiply textbox value with datagridview cell

查看:121
本文介绍了将文本框值与datagridview单元相乘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将文本框中的数字乘以datagridview单元格中的值?

我尝试过的事情:

到目前为止,我已经有了这段代码,不确定我是否遵循正确的原则...

Is it possible to multiply a number in my textbox by a value in the datagridview cell?

What I have tried:

So far I''ve got this code, not sure if I''m going along the correct lines...

e.Row.Cells[1].Value = (Convert.ToInt32(e.Row.Cells[1].Value) * Convert.ToInt32(OdrQuantityTxtBx.Text)).ToString(); //put the cell number as position in your gridview

推荐答案

将问题分成多个部分.
不必尝试完成单个操作,而是为每个部分定义和分配变量.

因此,第1部分:获取单元格值:e.Row.Cells [1] .Value)
在尝试将其转换为整数之前,请检查它是否为数字.
如果是,则将其转换,否则将其拒绝,不要尝试建立输出值

第2部分:获取文本框值:OdrQuantityTxtBx.Text
与第1部分一样,检查该值以查看它是否为数字

假设两个值都是数字,则产生结果:e * OdrQuantity

将其转换为字符串并替换您的单元格值.
Break the problem into multiple pieces.
Instead of trying to complete a single operation, define and assign variables for each portion.

So, part 1: get the cell value: e.Row.Cells[1].Value)
Before trying to convert in to an integer, check to see if it is numeric.
If it is, then convert it, otherwise reject it and don''t try to build an output value

Part 2: get the text box value: OdrQuantityTxtBx.Text
As with part 1, check the value to see if it is a number

Assuming both values are numeric, produce the result: e * OdrQuantity

Convert that to a string and replace your cell value.


这篇关于将文本框值与datagridview单元相乘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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