Home sort list of Controls from a custom class type
Reply: 1

sort list of Controls from a custom class type

Amir
1#
Amir Published in 2018-02-14 09:11:47Z

I have a problem in order my list, I check most of the example but I think my problem is unique. Please check and help me to get it done.

List<Control> lc = new List<Control>();

foreach (Control control in fLP.Controls)
{
   Dashboard_Env_Details ded =  (Dashboard_Env_Details)control;
   ded.refreshUC();
   lc.Add(control);
}

List<Control> Sortedlc = lc.OrderBy((o => ((Dashboard_Env_Details)o).custTask.getNoInvalidObjects).ToList();

I am receiving below error:

Severity Code Description Project File Line Suppression State Error CS0411 The type arguments for method 'Enumerable.OrderBy(IEnumerable, Func)' cannot be inferred from the usage. Try specifying the type arguments explicitly. KeepMyServerInfo C:\Users\CM_Dashboard.cs 141 Active

Tim Schmelter
2#
Tim Schmelter Reply to 2018-02-14 10:10:55Z

You have too many left parentheses. I would use OfType or Cast or store the controls in a List<Dashboard_Env_Details> instead:

List<Control> Sortedlc = lc.Cast<Dashboard_Env_Details>()
 .OrderBy(o => o.custTask.getNoInvalidObjects)
 .Select(o => (Control) o)
 .ToList();

If the list contains also other controls you could use OfType.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.30424 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO