Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Grid View, Click On Check Box Column

Status
Not open for further replies.

Auguy

Programmer
May 1, 2004
1,206
US
VB 2008 invoice screen. Bound data grid view to invoice detail table.
The detail records maintain the taxable status (IsTaxableColNbr) of the line item so if the customer Tax Rate changes the totals can be recalculated.
The Tax Rate may be zero.
When I click on the check box column (IsTaxableColNbr) everything works perfectly.
But if I click too fast the second click doesn't work properly and results in incorrect taxable/non-taxable totals.
I've tried using
Code:
Convert.ToBoolean(dgvr.Cells(IsTaxableColNbr).EditedFormattedValue)
directly but that didn't work either.
Also tried EndEdit and CancelEdit in various places with no luck.
Also tried using a variable to indicate this process isn't complete.
Am I missing something here?
What do I need to do to make this work?
Code:
  Private Sub dgvDetail_CellContentClick(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs) Handles dgvDetail.CellContentClick
    If e.ColumnIndex = IsTaxableColNbr And e.RowIndex >= 0 Then
      Dim RowNbr As Integer = e.RowIndex
      Dim CurrentExtValue As Decimal
      Dim TaxRate As Decimal

      TaxRate = CDec(dtInvoiceMaster.Rows(0).Item("TaxRate"))

      Dim dgvr As DataGridViewRow
      dgvr = dgvDetail.Rows(RowNbr)

      dgvr.Cells(IsTaxableColNbr).Value = Convert.ToBoolean(dgvr.Cells(IsTaxableColNbr).EditedFormattedValue)

      If dgvr.Cells(ExtPriceColNbr).Value Is DBNull.Value Then
        CurrentExtValue = gDecimalZero
      ElseIf CStr(dgvr.Cells(ExtPriceColNbr).Value).Trim = "" Then
        CurrentExtValue = gDecimalZero
      Else
        CurrentExtValue = CDec(dgvr.Cells(ExtPriceColNbr).Value)
      End If

      If Not TaxRate = gDecimalZero Then
        If Convert.ToBoolean(dgvr.Cells(IsTaxableColNbr).Value) = True Then
          dtInvoiceMaster.Rows(0).Item("NonTaxableTotal") = CDec(dtInvoiceMaster.Rows(0).Item("NonTaxableTotal")) - CurrentExtValue
          dtInvoiceMaster.Rows(0).Item("TaxableTotal") = CDec(dtInvoiceMaster.Rows(0).Item("TaxableTotal")) + CurrentExtValue
        Else
          dtInvoiceMaster.Rows(0).Item("NonTaxableTotal") = CDec(dtInvoiceMaster.Rows(0).Item("NonTaxableTotal")) + CurrentExtValue
          dtInvoiceMaster.Rows(0).Item("TaxableTotal") = CDec(dtInvoiceMaster.Rows(0).Item("TaxableTotal")) - CurrentExtValue
        End If
      End If

      ReCalcInvoice()
    End If
  End Sub
Detail grid is bound as follows to a binding source
Code:
 bsInvoiceDetail.DataSource = dtInvoiceDetail
dgvDetail.DataSource = bsInvoiceDetail

Auguy
Sylvania/Toledo Ohio
 
if I click too fast the second click doesn't work properly " - just a guess here, but maybe first click is not done processing yet.... [ponder]
If so, you may try to speed it up by thread222-1691060
Or, set a flag (Boolean) to allow the process only when certain value of this flag...


---- Andy

There is a great need for a sarcasm font.
 
Yes I'm pretty sure that is the case.
I've tried the flag option, it stopped the procedure but still changed the checkbox in the grid.
Doing more searches now.

Auguy
Sylvania/Toledo Ohio
 
I may have it solved, still testing, working so far.
I moved all of the code to do the calculations to
Code:
Private Sub dgvDetail_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvDetail.CellValueChanged
and reduced the CellContentClick to
Code:
  Private Sub dgvDetail_CellContentClick(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs) Handles dgvDetail.CellContentClick
    If e.ColumnIndex = IsTaxableColNbr And e.RowIndex >= 0 Then
      dgvDetail.EndEdit()
    End If
  End Sub
the cellvaluechanged won't fire until endedit is called.

Auguy
Sylvania/Toledo Ohio
 
Better, but still not working

Auguy
Sylvania/Toledo Ohio
 
the flag option, it stopped the procedure but still changed the checkbox in the grid."
So, if you can stop the procedure with this flag, then change the checkbox's value back in the grid as well. :)


---- Andy

There is a great need for a sarcasm font.
 
I will try that

Auguy
Sylvania/Toledo Ohio
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top