Zennher
Zennher

Reputation: 9

How to hide columns in a grid using Entity Framework in C# windows form

I am a beginner programmer and have to use Entity Framework for a project,

I am using the following code to populate a Datagrid :

private void Inscription_Load(object sender, EventArgs e)    
{
    using (receptionEntities oProxy = new receptionEntities())
    {
        List<P_ShowPotentialReception_Result> oQuery = 
            oProxy.P_ShowPotentialReception(MainForm.seq_no).ToList();

        foreach (P_ShowPotentialReception_Result objrecep in oQuery)
        {
            Console.WriteLine(objrecep.Rec_seq_no);
        }
        dataGrid3.DataSource = oQuery.ToList();
    }
}

The console.writeline is just there to check that the values have been gone through.

Two questions :
1) Is there a way to hide the columns I dont want to be shown for the user in this grid?

2) Is there a way to customize the background colors of a row depending on one of the columns info when you use Entity Framework to populate?

Upvotes: 1

Views: 599

Answers (1)

BeardedMan
BeardedMan

Reputation: 394

You can use projection to select just what you need, like this:

var result = oProxy.P_ShowPotentialReception(MainForm.seq_no).Select(r=> new { ID = r.Id, SequenceNumber = r.Rec_seq_no}).ToList();

foreach(var obj in result) 
{
   Console.WriteLine(obj.SequenceNumber);
}

or did I understand wrong your first question?

to change the color you can use this event

Upvotes: 1

Related Questions