1

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?

vard
  • 4,057
  • 2
  • 26
  • 46
Zennher
  • 9
  • 3
  • All of the stuff you want to do is not controlled by entity framework, but is controlled by the grid you are binding the data too. What framework is this? I'm assuming WinForms given you didn't have to call DataBind() on your grid. Anyways, if you have a DataGridView on a form, you can set up the columns in the designer after setting up a DataSource (again with the designer) – The Sharp Ninja Dec 18 '15 at 08:36

1 Answers1

1

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

Community
  • 1
  • 1
BeardedMan
  • 384
  • 2
  • 12
  • Thank you the projection worked fine ! But i have problems with the color i can't seem to find the rowdata_bound event for my Windows form. – Zennher Dec 18 '15 at 12:02
  • @Zennher Sorry I thought you are using web control. For WinForms you should go with [this](http://stackoverflow.com/a/4067612/3405032) – BeardedMan Dec 18 '15 at 12:11