Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to be able to make rows not visible if the checkbox value =0
so far, I get a currency mananger error message.
I have looked around a bit, but can't seem to get any of the posted solutions to work for me.

here is the code:
For i As Integer = 0 To DataGridView1.Rows.Count - 1
           For s As Integer = 0 To app.Services.Count - 1
               If app.Services(s).Serviceid = Int32.Parse(DataGridView1.Rows(i).Cells("serviceid").Value.ToString()) Then
                   Dim chkcell As DataGridViewCheckBoxCell = CType(DataGridView1.Rows(i).Cells("cbcServiceChecked"), DataGridViewCheckBoxCell)

                   DataGridView1.Rows(i).Cells("cbcServiceChecked").Value = 1
                   chkcell = Nothing
                   'Else : DataGridView1.Rows(i).Cells("cbcServiceChecked").Value = 0
                   '    DataGridView1.Rows(i).Visible = False

               End If


           Next

       Next
Posted
Updated 15-Jun-10 8:23am
v2

Handling the DataGridView.CellValueChanged event worked for me.

VB
Private Sub DataGridView1_CellValueChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
    If e.RowIndex < 0 Then
        Exit Sub ' guard against firing during initialization
    End If
    If e.ColumnIndex = chboxclmShow.Index Then
        If Me.DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = False Then
            Me.DataGridView1.CurrentCell = Nothing ' CurrencyManager Exception without this line
            Me.DataGridView1.Rows(e.RowIndex).Visible = False
        End If
    End If
End Sub


If you go this way remember that the event will not fire until you leave the cell.
chboxclmShow is the CheckBoxColumn
 
Share this answer
 
A various number of options are discussed in this post. Maybe one of them can help you.
 
Share this answer
 
Private Sub Filter()
For i As Integer = 0 To DataGridView1.Rows.Count - 1
If DataGridView1.Rows(i).Cells("cbcServiceChecked").Value = 0 Then
Me.DataGridView1.CurrentCell = Nothing
Dim band As DataGridViewBand = DataGridView1.Rows(i)
band.Visible = False
End If
Next
End Sub

This really is the easiest way to do it, then call the filter in the load event.
It hides the band of cells while keeping the row intact..from msdn.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900