需要帮助将代码转换为vb.net [英] need help to convert code to vb.net
本文介绍了需要帮助将代码转换为vb.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经搜索了很长时间的代码,我发现这个 如果数据已经存在,则网格视图添加数量。 [ ^ ]
\但代码不是vb.net我想帮你把这个代码转换成vb.net
i have searched for code for long time and i found this Grid View add quantity if data already exists..[^]
\but code not vb.net i want help to convert this code to vb.net
//Boolean to check if he has row has been
bool Found = false;
if (dataGridView.Rows.Count > 0)
{
//Check if the product Id exists with the same Price
foreach (DataGridViewRow row in dataGridView.Rows)
{
if (Convert.ToString(row.Cells[0].Value) == textBox_ProductId.Text && Convert.ToString(row.Cells[1].Value) == textBox_Price.Text)
{
//Update the Quantity of the found row
row.Cells[2].Value = Convert.ToString(1 + Convert.ToInt16(row.Cells[2].Value));
Found = true;
}
}
if (!Found)
{
//Add the row to grid view
dataGridView.Rows.Add(textBox_ProductId.Text, textBox_Price.Text, 1);
}
}
else
{
//Add the row to grid view for the first time
dataGridView.Rows.Add(textBox_ProductId.Text, textBox_Price.Text, 1);
}
推荐答案
有些网络应用可以为您进行转换,例如Telerik Code Converter [ ^ ],它提供以下VB.NET代码:
There are web apps which can do the conversion for you, such as Telerik Code Converter[^], which gives the following VB.NET code:
'Boolean to check if he has row has been
Dim Found As Boolean = False
If dataGridView.Rows.Count > 0 Then
'Check if the product Id exists with the same Price
For Each row As DataGridViewRow In dataGridView.Rows
If Convert.ToString(row.Cells(0).Value) = textBox_ProductId.Text AndAlso Convert.ToString(row.Cells(1).Value) = textBox_Price.Text Then
'Update the Quantity of the found row
row.Cells(2).Value = Convert.ToString(1 + Convert.ToInt16(row.Cells(2).Value))
Found = True
End If
Next
If Not Found Then
'Add the row to grid view
dataGridView.Rows.Add(textBox_ProductId.Text, textBox_Price.Text, 1)
End If
Else
'Add the row to grid view for the first time
dataGridView.Rows.Add(textBox_ProductId.Text, textBox_Price.Text, 1)
End If
这篇关于需要帮助将代码转换为vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文