Olukayode Oluwole
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)
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_CellValueC hanged(obj ect sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 1)
{
switch (this.dgvDetailsTable.Colu mns[e.Colu mnIndex].N ame)
{
case "dgvcmbarsaleditemid":
var result = ((List<InventoryItemModel> )dgvcmbars aleditemid .DataSourc e).Find(x => x.INVITEMId.Equals(dgvcmba rsaleditem id.Selecte d));
this.dgvDetailsTable.Curre ntRow.Cell s[2].Value = result.INVITEMDescription;
break;
}
}
}[/code]
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
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
Whats wrong with my LAMDA expression and how can i correct it
Thanks for any assistance
Olukay
The Display Value in column 1 has an ID and Description ( see screen below)
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_CellValueC
{
if (e.ColumnIndex == 1)
{
switch (this.dgvDetailsTable.Colu
{
case "dgvcmbarsaleditemid":
var result = ((List<InventoryItemModel>
this.dgvDetailsTable.Curre
break;
}
}
}[/code]
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
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
Whats wrong with my LAMDA expression and how can i correct it
Thanks for any assistance
Olukay
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I found out the syntax isssue
Thanks