locked
how to invisible a row of Datagridview ? RRS feed

  • Question

  • 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 ?

    Saturday, March 31, 2007 9:04 AM

Answers

  • 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;

    Sunday, April 1, 2007 4:38 PM

All replies

  • 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;

    Sunday, April 1, 2007 4:38 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.

    Wednesday, February 27, 2008 2:58 PM
  • You can put the

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

    condition in DataGridView_MouseUp event
    Tuesday, March 4, 2008 2:11 PM
  • thanks alot vic!
    Thursday, April 10, 2008 9:07 AM
  • "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.
    Monday, May 5, 2008 8:42 PM
  • Thanks it works...

    Wednesday, July 2, 2008 11:13 AM
  • 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
    Thursday, June 18, 2009 3:34 PM
  • wrong thread...
    • Proposed as answer by FrankyHollywood Saturday, November 13, 2010 7:33 AM
    Saturday, November 13, 2010 7:33 AM
  • Tank you!!! Worked perfectly.
    Tuesday, July 5, 2011 5:28 AM
  • Thank you!!

    It helped.


    • Edited by PavelJ_CZ Thursday, February 16, 2012 10:50 AM
    Thursday, February 16, 2012 10:50 AM
  • thank you
    Sunday, March 18, 2012 10:36 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();


    Monday, June 4, 2012 4:06 PM
  • it works for me

    cheers

    Thursday, July 5, 2012 4:47 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
    Wednesday, October 10, 2012 4:24 AM