Question

I have a datagrid with a combobox. This combobox has numbers and text in it. I want to place a condition that if the combobox text is BOGO or Complimentary, then my variable dblQty should be 0.

I am able to get it to work for one condition BOGO, (see code below), but I can't seem to get it to work with 2 conditions, I tried BOGO Or Complimentary but I got a cannot convert to Boolean error.

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
Was it helpful?

Solution

Based on the passing comment in the post that I tried BOGO Or Complimentary it sounds like you may have tried this:

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

Which is not how OR works. The second test can be for something altogether different such as

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

Try this:

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

If thing = "BOGO" Or Thing = "Complimentary" Then...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top