×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Data Grid View, Click On Check Box Column

Data Grid View, Click On Check Box Column

Data Grid View, Click On Check Box Column

(OP)
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

RE: Data Grid View, Click On Check Box Column

"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: Redraw in DataGridView
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.

RE: Data Grid View, Click On Check Box Column

(OP)
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

RE: Data Grid View, Click On Check Box Column

(OP)
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

RE: Data Grid View, Click On Check Box Column

(OP)
Better, but still not working

Auguy
Sylvania/Toledo Ohio

RE: Data Grid View, Click On Check Box Column

"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. smile


---- Andy

There is a great need for a sarcasm font.

RE: Data Grid View, Click On Check Box Column

(OP)
I will try that

Auguy
Sylvania/Toledo Ohio

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close