【问题标题】:Convert multiple values on datagrid to string on If condition在 If 条件下将 datagrid 上的多个值转换为字符串
【发布时间】:2014-04-29 19:05:58
【问题描述】:

我有一个带有组合框的数据网格。此组合框包含数字和文本。我想设置一个条件,如果组合框文本是 BOGO 或 Complimentary,那么我的变量 dblQty 应该是 0。

我可以让它在一个条件下工作 BOGO,(见下面的代码),但我似乎无法让它在两个条件下工作,我试过 BOGO Or Complimentary 但我得到了一个无法转换为布尔值错误。

Private Sub grdNewInvoice_CurrentCellDirtyStateChanged(sender As Object, e As EventArgs) Handles grdNewInvoice.CurrentCellDirtyStateChanged

    'Procedure runs when the combobox in the datagrid changes. 
    'The procedure calculates the amount * the quantity in the datagrid
    'It also updates the label with the total

    'Local variables
    Dim dblQty As Double
    Dim dblPrice As Double

    'Calculate the amount * quantity
    For index As Integer = 0 To grdNewInvoice.RowCount - 1

        If grdNewInvoice.Rows(index).Cells(1).Value.ToString = "BOGO" Then

            dblQty = 0
            dblPrice = Convert.ToDouble(grdNewInvoice.Rows(index).Cells(2).Value)

            grdNewInvoice.Rows(index).Cells(3).Value = dblPrice * dblQty

        Else

            dblQty = Convert.ToDouble(grdNewInvoice.Rows(index).Cells(1).Value)
            dblPrice = Convert.ToDouble(grdNewInvoice.Rows(index).Cells(2).Value)

            grdNewInvoice.Rows(index).Cells(3).Value = dblPrice * dblQty

        End If

    Next

    'Update the total label.
    PublicSubs.totalDataGrid()

End Sub

【问题讨论】:

  • 你为BOGO Or Complimentary尝试的代码是什么??

标签: vb.net datagrid


【解决方案1】:

根据I tried BOGO Or Complimentary 帖子中传递的评论,听起来您可能已经尝试过:

If grdNewInvoice.Rows(index).Cells(1).Value.ToString = "BOGO" 
          Or "Complimentary" Then

这不是 OR 的工作方式。第二个测试可以是完全不同的东西,例如

If thisThing = "BOGO" Or Sale.BlackFriday = True Then ...

试试这个:

Dim thing As String = grdNewInvoice.Rows(index).Cells(1).Value.ToString 

If thing = "BOGO" Or Thing = "Complimentary" Then...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-06
    • 2022-11-23
    • 2020-05-22
    • 1970-01-01
    • 2021-06-21
    • 2019-10-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多