Add object to a BindingList in a BindingList

I have a bindinglist of activity, and each activity has a bindinglist of BuyOrders

bindingListActivty.Select(k => k._dataGridViewId == 1);

If I understand correctly, i can select the activity, but I cannot access any method inside the activity. How do I access the method without creating a new instance of a bindinglist ?

I tought this would work, but no

bindingListActivty.Select(k => k._dataGridViewId == 1).addBuyOrders(new BuyOrders());


You could try this one:

// Get the activity from bindingListActivity, whose k._dataGridViewId is equal to 1.
var activity = bindingListActivty.SingleOrDefault(k => k._dataGridViewId == 1);

// If the activity has been found and the a new BuyOrders object.
    activity.addBuyOrders(new BuyOrders());

Select returns an IEnumerable<T>, which will not have your addBuyOrders method. You need to either use a foreach or you could use FirstOrDefault with a Where clause to get the individual object that exposes the method.

For example:


var activities = bindingListActivty.Select(k => k._dataGridViewId == 1);
foreach(var a in activities)
    a.addBuyOrders(new BuyOrders());

FirstOrDefault (this likely makes more sense based on your where clause):

var activity = bindingListActivty.Where(k => k._dataGridViewId == 1).FirstOrDefault();
if (activity != null)
    activity.addBuyOrders(new BuyOrders());

Need Your Help

How to set ConnectionTimeout to 0 in Sql Server 2008?

sql-server odbc

I set timeout to 0 but the connection close prematuraly, what is wrong with this statement ?

TDD, Matrix Additions Not Working

java matrix tdd

Lowdown: Beginning Java course. Lecture has been about collections, and nothing really too difficult in concept. All theory, not blood and guts coding.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.