Click here to Skip to main content
15,886,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a DatagridView.
I have set its DataSource From a Class.

C#
taskerEntities te = new taskerEntities();
var OMsMasterDescriptiveIndicators = te.MyTable.Select(x => new lccls {Id = x.Id, name = x.name }).ToList();
MyGrid.DataSource = OMsMasterDescriptiveIndicators;

My Class is like
C#
public class lccls
    {
        public string Id { get; set; }
        public Nullable<decimal> name { get; set; }
    }


At a certain event, I want to Visible = False the current row.
C#
MyGrid.Rows[5].Visible = false;


But I am unable to do this. I think the reason is it's `datasource` associated.
So can you please help me.
How could I do this?
Is what I think about this problem is correct or not?

The Error is
>   Row associated with the currency manager's position cannot be made<br />
> invisible
Posted
Updated 31-Mar-23 0:32am
v3

A Google search found this[^] answer.

It looks like you have to suspend binding and then resume binding. I adapted example from the web page found at the link above.

CurrencyManager currencyManager1 = (CurrencyManager)BindingContext[MyGrid.DataSource];
currencyManager1.SuspendBinding();
MyGrid.Rows[5].Visible = false;
currencyManager1.ResumeBinding();
 
Share this answer
 
Comments
Co. Aden 22-Sep-13 5:40am    
thanks alot mike meinz it works..
A_Griffin 29-Oct-17 4:31am    
I know this is a very old post, but just stumbled across it, and wanted to point out an easier way - just set this instead before setting the visibility:
MyGrid.CurrentCell = Nothing
Chase Viking 25-Oct-18 13:29pm    
But then if you wanted to show it again, you cannot. So, no.
maybe this is old but:
@A_Griffin
yes this way is better and there is no problem with making it visible again (@Chase Viking).

Example:
C#
var item = dgv.Rows.Cast<DataGridViewRow>().FirstOrDefault(c => c.Cells[x].Value?.ToString() == X);
            if (item != null)
            {
                availableIpsDataGridView.CurrentCell = null;
                item.Visible = false;
            }

and visibling it with:
C#
var item = dgv.Rows.Cast<DataGridViewRow>().FirstOrDefault(c => c.Cells[x].Value?.ToString() == X);
                if (item != null)
                {
                    item.Visible = true;
                }
 
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