error-cannot check the checkbox in datagrid after 2nd search
-
Hi, I have a datatable retrieve data in a datagrid with a checkbox column bounded to it. On the 1st data retrieval on datagrid, I'm able to check the checkbox. But if i click search to have 2nd data retrieval on datagrind, I'm unable to check the checkbox. Below is my code, i hope someone can guide me to solve this. Private selectedRows As ArrayList Private Sub dgResult_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Dim hit As DataGrid.HitTestInfo = dgResult.HitTest(e.X, e.Y) If hit.Column = 0 AndAlso hit.Type = DataGrid.HitTestType.Cell Then dgResult(hit.Row, hit.Column) = Not CBool(dgResult(hit.Row, hit.Column)) If CBool(dgResult(hit.Row, hit.Column)) Then selectedRows.Add(hit.Row) dgResult.[Select](hit.Row) Else selectedRows.Remove(hit.Row) End If End If End Sub I did run step by step to check the error. When the 2nd retrieval, it run through the codes twice. 1st, it run Private Sub dgResult_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) If hit.Column = 0 AndAlso hit.Type = DataGrid.HitTestType.Cell Then dgResult(hit.Row, hit.Column) = Not CBool(dgResult(hit.Row, hit.Column)) If CBool(dgResult(hit.Row, hit.Column)) Then selectedRows.Add(hit.Row) dgResult.[Select](hit.Row) end if end sub then continue to run it again but this time to remove the check. Private Sub dgResult_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) If hit.Column = 0 AndAlso hit.Type = DataGrid.HitTestType.Cell Then dgResult(hit.Row, hit.Column) = Not CBool(dgResult(hit.Row, hit.Column)) If CBool(dgResult(hit.Row, hit.Column)) Then selectedRows.Remove(hit.Row) end if end sub So, it seems i cannot check. But in actual, it added the check and removed the check at the same time. Can anyone help me? Thanks. eunice