![]() |
Click here to advertise with us
|
|
|||||||
| Winforms Grids Discussion related to grid controls of all types for Winforms |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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 6:53 PM. |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|