troubleshooting Question

How Do I change a Cast Statement made from a Generic List to another List made from a Binding List

Avatar of Olukayode Oluwole
Olukayode OluwoleFlag for Canada asked on
* GridC#
4 Comments1 Solution12 ViewsLast Modified:
I have a C# application in which i loaded a Generic List to a  Grid Column using the script below. The Load  of the List worked.

dgvcmbarsaleditemid.DataSource = GlobalConfig.Connection.GetInventoryItems_All();
dgvcmbarsaleditemid.DisplayMember = "FullInventoryList";
dgvcmbarsaleditemid.ValueMember = "INVITEMId";

The Cast statement  below  also worked  perfectly

var result2 = ((List<InventoryItemModel>)dgvcmbarsaleditemid.DataSource).Find(x => x.INVITEMId == Convert.ToString(dgvDetailsTable.CurrentRow.Cells["dgvcmbarsaleditemid"].Value));

However I have  changed my mode of loading the same Column by using a Binding List.
And the List also loaded properly in the Grid. The code is shown below

BindingList<InventoryItemModel> inventoryitems = new BindingList<InventoryItemModel>();  // for new method


var parameter07 = new { companycodex = LoginDetails.staticcompany };
var newList7 = NewDataAccess.ReadData<InventoryItemModel>("public.spinventory_getall", parameter07);
dgvcmbarsaleditemid.DataSource = null;
dgvcmbarsaleditemid.DataSource = inventoryitems;
dgvcmbarsaleditemid.DisplayMember = "FullInventoryList";
dgvcmbarsaleditemid.ValueMember = "INVITEMId";
inventoryitems.Clear();                  // This line clears the customers list box
newList7.ForEach(x => inventoryitems.Add(x));

Now  my Cast statement now reports an error that the Cast Statement Using a Generic List
is now invalid because the List is prepared as a Binding List  ( see   error  below )


The Line commented out worked when i had a Generic List

What modification do i need to make the Cast statement valid now that i have a Binding List

Thanks

Olukay


ASKER CERTIFIED SOLUTION
Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 4 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 4 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004