在VB Net中使行在运行时不可见(datagridview) [英] Make row invisible at runtime ( datagridview) in vb net

查看:279
本文介绍了在VB Net中使行在运行时不可见(datagridview)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果复选框值为= 0,我希望能够使行不可见
到目前为止,我收到了货币mananger错误消息.
我环顾了一下,但似乎无法获得任何已发布的解决方案来为我工作.

这是代码:

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

推荐答案

处理DataGridView.CellValueChanged事件对我来说很有效.

Handling the DataGridView.CellValueChanged event worked for me.

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



如果您采用这种方式,请记住,直到您离开牢房,该事件才会触发.
chboxclmShowCheckBoxColumn



If you go this way remember that the event will not fire until you leave the cell.
chboxclmShow is the CheckBoxColumn


A various number of options are discussed in this post. Maybe one of them can help you.


Private Sub Filter()
对于i As Integer = 0到DataGridView1.Rows.Count-1
如果DataGridView1.Rows(i).Cells("cbcServiceChecked").Value = 0然后
Me.DataGridView1.CurrentCell = Nothing
Dim band为DataGridViewBand = DataGridView1.Rows(i)
band.Visible = False
如果结束
下一个
结束子

这确实是最简单的方法,然后在load事件中调用过滤器.
它隐藏单元格区域,同时保持行完整..来自msdn.
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.


这篇关于在VB Net中使行在运行时不可见(datagridview)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆