Click here to Skip to main content
15,880,427 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have got 2 grids, one shows orders which are processing the other, orders which are pending; however it doesn't seem to be working, as all of the data in the grid appears


C#
foreach (DataGridViewRow dr in dataGridView4.Rows)
{
   int targetColumnIndex = 6;
   if (dr.Cells.Count > targetColumnIndex) // validate the index
      if (dr.Cells[targetColumnIndex].Value.ToString() == "Processing")
      {
         dr.Visible = false;
      }
}

foreach (DataGridViewRow dg in dataGridView1.Rows)
{
   int targetColumnIndex = 6;
   if (dg.Cells.Count > targetColumnIndex) // validate the index
      if (dg.Cells[targetColumnIndex].Value.ToString() == "Pending")
      {
         dg.Visible = false;
      }
}


What I have tried:

Re-writing code
change around processing / pending
Posted
Updated 7-Jan-18 9:02am
v6
Comments
CHill60 15-Dec-17 7:29am    
Where are you putting this code?
Member 13512434 15-Dec-17 7:42am    
What do you mean where am I putting the code?

It goes under ...
private void MainSystem_Load(object sender, EventArgs e)

if this answers your question
CHill60 15-Dec-17 8:10am    
Yes that answers my question. Are you inadvertently refreshing the datagridview after this code? When you debug, are you definitely hitting the line that is setting Visible = false?
Member 13512434 15-Dec-17 8:29am    
I am,

I'm now getting this message...

An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll

Additional information: Row associated with the currency manager's position cannot be made invisible.
Member 13512434 15-Dec-17 8:36am    
no worries, I needed to insert ...
dataGridView1.CurrentCell = null;

1 solution

Member 13512434 wrote:

I am,

I'm now getting this message...

An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll

Additional information: Row associated with the currency manager's position cannot be made invisible.


Seems your datagridview is bind with datasource. Well, i'd strongly recommend to filter binding source instead of hide datagridview rows.

In case you still want to hide rows, you have to add custom property to bindingsource. Please, refer these:
c# How to hide a row in a DataGridView with DataSource - Stack Overflow[^]
c# - Hide Row in DataGridView with Binding not working in my project - Stack Overflow[^]
 
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