Locked how to invisible a row of Datagridview ?

  • Saturday, March 31, 2007 9:04 AM
     
     

    hi
    i want to hide one or more row of datagridview that bind to dataset, but the following error shown me :

    Row associated with the currency manager's position cannot be made invisible

     

    how to solve this problem ?

All Replies

  • Sunday, April 01, 2007 4:38 PM
     
     Answered
    As I understand it this is because the currently selected cell/row must be visible, I got around it by simply setting the currently selected cell to null before hiding the row:

    Code Snippet

    dataGridView1.CurrentCell = null;

    dataGridView1.Rows[row].Visible = false;


    Hope that helps.

    *Edit* whoops, the currency manager problem is slightly more complicated than that:
    Since you are bound to a dataset all you have to do is suspend the binding on all the rows in the currency manager before setting them to invisible:

    Code Snippet

    CurrencyManager currencyManager1 = (CurrencyManager)BindingContect[dataGridView1.DataSource];

    currencyManager1.SuspendBinding();
    dataGridView1.Rows[row].Visible = false;

  • Wednesday, February 27, 2008 2:58 PM
     
     

    In VB.NET it goes like this:

     

    Code Snippet

    Me.DataGridView.CurrentCell = Nothing

    Me.DataGridView.Rows(index).Visible = False

     

     

     

    This worked for me perfectly with a databound grid.

    The only problem with this is that if the user wishes to sort the grid, it refreshes and makes all the rows visible again.

  • Tuesday, March 04, 2008 2:11 PM
     
     
    You can put the

    Me.DataGridView.Rows(index).Visible = False

    condition in DataGridView_MouseUp event
  • Thursday, April 10, 2008 9:07 AM
     
     
    thanks alot vic!
  • Monday, May 05, 2008 8:42 PM
     
     
    "Row associated with the currency manager's position cannot be made invisible."

    In VB.NET it goes like this:

     

    Code Snippet

    Me.DataGridView.CurrentCell = Nothing

    Me.DataGridView.Rows(index).Visible = False

     

     



    Yes, this is the method I used also.

    You will see in other forums, like here:

    http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.windowsforms/topic25641.aspx

    and here

    http://forums.microsoft.com/MSDN/ShowPost.aspx?siteid=1&PostID=51563

    that people recommend messing with the binding, but that just causes more problems, so I'd avoid that! I tried to reply on those threads when I found the solution, but I guess they are archived.

    Glad the right answer is here.
  • Wednesday, July 02, 2008 11:13 AM
     
     

    Thanks it works...

  • Thursday, June 18, 2009 3:34 PM
     
     Proposed
    that did not work for me. I got an index out of range error. This is what I did

                    int iRowIndex = this.uiActionDates.SelectedRows[0].Index;
                    this.uiActionDates.CurrentCell = null;
                    this.uiActionDates.Rows[iRowIndex].Visible = false;

    Luis Fleitas
    • Proposed As Answer by Free.Cracker Tuesday, January 18, 2011 12:10 PM
    •  
  • Saturday, November 13, 2010 7:33 AM
     
     Proposed
    wrong thread...
    • Proposed As Answer by FrankyHollywood Saturday, November 13, 2010 7:33 AM
    •  
  • Tuesday, July 05, 2011 5:28 AM
     
     
    Tank you!!! Worked perfectly.
  • Thursday, February 16, 2012 10:50 AM
     
     

    Thank you!!

    It helped.


    • Edited by PavelJ_CZ Thursday, February 16, 2012 10:50 AM
    •  
  • Sunday, March 18, 2012 10:36 PM
     
     
    thank you
  • Monday, June 04, 2012 4:06 PM
     
     
    As I understand it this is because the currently selected cell/row must be visible, I got around it by simply setting the currently selected cell to null before hiding the row:

    Code Snippet

    dataGridView1.CurrentCell = null;

    dataGridView1.Rows[row].Visible = false;


    Hope that helps.

    *Edit* whoops, the currency manager problem is slightly more complicated than that:
    Since you are bound to a dataset all you have to do is suspend the binding on all the rows in the currency manager before setting them to invisible:

    Code Snippet

    CurrencyManager currencyManager1 = (CurrencyManager)BindingContect[dataGridView1.DataSource];

    currencyManager1.SuspendBinding();
    dataGridView1.Rows[row].Visible = false;

    // Wanted to add the resume statement to make it complete. Thank You for the solution, this works perfect!

    currencyManager1.ResumeBinding();


  • Thursday, July 05, 2012 4:47 AM
     
     

    it works for me

    cheers

  • Wednesday, October 10, 2012 4:24 AM
     
     

    It works fine,

    but very slow, 10,000 rows(Visible or Invisble) takes 1 mint of time

    Please

    Thanks


    • Edited by Reddiyar Wednesday, October 10, 2012 4:25 AM
    •