NewBie
NewBie

Reputation: 1844

How to find an object from a List of objects?

I got a list of columns in the variable ParentColumnNames, i need to find a single Column object within this list using the selectedvalue of another combobox. How can i get that? Please help...

List<Columns> ParentColumnNames = new List<Columns>();
     ParentColumnNames = metadataobj.GetColumns(cbParentTable.SelectedItem.ToString());

within this i need to find single object using cbParentColumn.SelectedValue.

Upvotes: 2

Views: 579

Answers (1)

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174289

Try something like this:

ParentColumnNames.Where(x => x.Name == cbParentColumn.SelectedValue).FirstOrDefault();

My answer assumes that the Columns class has a property Name and that this property contains the value you are looking for.

Upvotes: 2

Related Questions