Hidding rows in the DataGridView is too slow

Costas

Administrator
Staff member
by Darko Matesic - Subclassing DataGridView and overriding OnRowStateChanged method. When Suspended property is set to false one row is needed to change it's visibility so grid is properly updated.

C#:
--src - https://social.msdn.microsoft.com/Forums/windows/en-US/68c8b93e-d273-4289-b2b0-0e9ea644623a/
private class DataGridViewEx: DataGridView
{
    private bool m_Suspended = false;
    public bool Suspended
    {
        get { return m_Suspended; }
        set
        {
            if(m_Suspended != value) {
                m_Suspended = value;
                if(!m_Suspended && this.Rows.Count > 0) {
                    bool visible = this.Rows[0].Visible;
                    this.Rows[0].Visible = !visible;
                    this.Rows[0].Visible = visible;
                }
            }
        }
    }

    protected override void OnRowStateChanged(int rowIndex, DataGridViewRowStateChangedEventArgs e)
    {
        if(!m_Suspended) base.OnRowStateChanged(rowIndex, e);
    }
}
 
Top