+ Reply to Thread
Results 1 to 1 of 1

Thread: dgv checkbox problem

  1. #1
    jamie123 is offline VB.NET Forum Enthusiast jamie123 is on a distinguished programming path ahead
    .NET Framework
    .NET 3.0 (VS 2005/2008)
    Join Date
    May 2008
    Posts
    82
    Reputation
    31

    Default dgv checkbox problem

    I'm using a datagridview on vs2008 programming with vb.net. The datagridview is populated from a sql server 2005 database. There is a checkbox for one of the columns (it's of boolean type). I used the following code to determine whether the checkbox is being selected or unselected, it worked in my other programs, but in my current program, it ALWAYS shows the checkbox as having a false value, not sure what's going on..

    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
    Dim dgCB As New DataGridViewCheckBoxCell
    Dim Value As Boolean
    Dim dgCBTax As New DataGridViewCheckBoxCell
    Dim ValueTax As Boolean
    If e.RowIndex = -1 Then
    Exit Sub
    End If
    Value = DataGridView1(e.ColumnIndex, e.RowIndex).Value.ToString()
    dgCB = CType(DataGridView1(e.ColumnIndex, e.RowIndex), DataGridViewCheckBoxCell)

    If e.ColumnIndex = 2 then
    If Value = False And dgCB.EditingCellValueChanged Then
    ID = DataGridView1(0, e.RowIndex).Value.ToString
    ElectronicClaimTableAdapter.UpdateSendtoTrue(ID) 'Updates value of checkbox column to true since it was previously false, and clicked
    MsgBox("hello")
    Else
    ID = DataGridView1(0, e.RowIndex).Value.ToString
    ElectronicClaimTableAdapter.UpdateSendtoFalse(ID) 'Updates value of checkbox column to false since it was previously true, and clicked
    MsgBox("goodbye")
    End If
    End If


    End Sub

    any help would be greatly appreciated, thanks! (I know there are inefficiencies in the code above, but I don't understand why the checkbox is always reporting a value of false)

    EDIT: I've found the solution, BUT, it makes my form laggish, i'll explain why. I refilled the dataset after the condtional statements, example (all of below is an excerpt from above except bolded text:

    If Value = False And dgCB.EditingCellValueChanged Then
    ID = DataGridView1(0, e.RowIndex).Value.ToString
    ElectronicClaimTableAdapter.UpdateSendtoTrue(ID) 'Updates value of checkbox column to true since it was previously false, and clicked
    MsgBox("hello")
    Me.ElectronicClaimTableAdapter.Fill(EyeBaseDataSet .ElectronicClaim)


    This updates the datagridview, and now the correct messageboxes appear when checked on or checked off, but, everytime i check, the scroll bar resets to the top. It is very annoying to check a checkbox with the scrollbar halfway down, and then check a box, and have it reset your scroll position, how could this be avoided?

    Thank you!
    Last edited by jamie123; 06-11-2009 at 5:53 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts