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
C#* Grid
4 Comments1 Solution8 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
it_saige
Developer
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros