Link to home
Start Free TrialLog in
Avatar of Olukayode Oluwole
Olukayode OluwoleFlag for Canada

asked on

Whats wrong with my LINQ query Trying to Find a Record in List

I have this Grid in my c# application

The Display Value in column 1  has an ID and Description  ( see  screen below)

User generated image

When i change values in column1 I want the description written into column2

I am trying to use LINQ  and a LAMDA Expression  . My script is as shown below

[private void dgvDetailsTable_CellValueChanged(object sender, DataGridViewCellEventArgs e)
            if (e.ColumnIndex == 1)

                switch (this.dgvDetailsTable.Columns[e.ColumnIndex].Name)
                    case "dgvcmbarsaleditemid":
                        var result = ((List<InventoryItemModel>)dgvcmbarsaleditemid.DataSource).Find(x => x.INVITEMId.Equals(dgvcmbarsaleditemid.Selected));
                        this.dgvDetailsTable.CurrentRow.Cells[2].Value = result.INVITEMDescription;



My database  field name is INVITEMId   and my   DataGrid  column 1 name is   dgvcmbarsaleditemid.

In the debugger  I can see that the 1188 records  were selected  and in the debugger i can see the loop search going on

See  Debugger  Screen below

User generated image

At the end of the looping it can not find the selected record and put it in the result variable even though the selected record
is on screen and coming from the database.  See  Error screen below

User generated image
Whats wrong with my LAMDA  expression  and how can i correct it

Thanks for any assistance

Avatar of gr8gonzo
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Olukayode Oluwole


No It wasnt

I found out the syntax isssue