如何使用datagridview coloum减去文本框值 [英] How to Subtract textbox value with datagridview coloum..

查看:130
本文介绍了如何使用datagridview coloum减去文本框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hy大家

我的vb项目需要帮助

最后一天我创建了股票数据库

数据库有2个coloums第1个项目名称第2个数量

在我的表格中我有两个文本框与数据库和一个按钮相同

按下按钮时

如果我的Itemname文本框与数据库coloum {itemname}匹配,则Quantity Textbox减去Quantitycoloum

如果与数据库itemname coloum相匹配[2] coloum2数量减去Quantitytextbox

这里我的代码工作但是很冗长: -



Hy everyone
I need help for my vb project
last day i created stock database
the database have 2 coloums 1st"Item Name" 2nd "Quantity"
In my form i Have two textboxes same as database and a button
when button press
if my "Itemname textbox" match with database coloum{itemname} then "Quantity Textbox" subtract with "Quantitycoloum"
if match with database "itemname coloum"[2] the coloum2 quantity subtract with "Quantitytextbox"
here My Code its work but So Lengthy:-

If itemname.Text = Me.DataGridView1.Rows(0).Cells(0).Value Then
            Me.DataGridView1.Rows(0).Cells(1).Value = CDbl(Me.DataGridView1.Rows(0).Cells(1).Value) - CDbl(quantity.Text)
            MsgBox("Data Saved SuccessFully")
            quantity.Text = ""
            itemname.Text = ""

        ElseIf itemname.text = Me.DataGridView1.Rows(1).Cells(0).Value Then
            Me.DataGridView1.Rows(1).Cells(1).Value = CDbl(quantity.Text) - CDbl(Me.DataGridView1.Rows(1).Cells(1).Value)
            MsgBox("Data Saved SuccessFully")
            quantity = ""
            itemname.Text = ""

        ElseIf itemname.Text = Me.DataGridView1.Rows(2).Cells(0).Value Then
            Me.DataGridView1.Rows(2).Cells(1).Value = CDbl(quantity.Text) - CDbl(Me.DataGridView1.Rows(2).Cells(1).Value)
            MsgBox("Data Saved SuccessFully")
            quantity = ""
            itemname.Text = ""


        ElseIf itemname.Text = Me.DataGridView1.Rows(3).Cells(0).Value Then
            Me.DataGridView1.Rows(3).Cells(1).Value = CDbl(quantity.Text) - CDbl(Me.DataGridView1.Rows(3).Cells(1).Value)
            MsgBox("Data Saved SuccessFully")
            quantity.Text = ""
            itemname.Text = ""

          endif
end sub
And So on.......
PLEASE HELP ....

推荐答案

For Each row As DataRow In Me.DataGridView1.Rows
	If itemname.Text = row.Cells(0).Value Then
		row.Cells(1).Value = Convert.ToDouble(row.Cells(1).Value) - Convert.ToDouble(quantity.Text)
		Interaction.MsgBox("Data Saved SuccessFully")
		quantity.Text = ""
		itemname.Text = ""
		Exit For
	End If
Next





For Each ... Next Statement(Visual Basic) [ ^ ]


这篇关于如何使用datagridview coloum减去文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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