Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8396405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:31:38+00:00 2026-06-09T20:31:38+00:00

Couldn’t the following code be done (and done better) with LINQ/func delegate? I’m fairly

  • 0

Couldn’t the following code be done (and done better) with LINQ/func delegate? I’m fairly new to LINQ/func. I’m looping through all the controls on the form to find all the FlowLayoutPanels (they’re embedded in tabs and split containers) and saving the control index information to the application settings so it can be recalled upon loading. My app allows the user to reposition their GUI/controls with drag drop. *Note, ServicingLayout is my own serializable class with info I need to restore the user’s preference.

Private Sub SaveFlow(ByVal F As FlowLayoutPanel) Handles Me.FoundFlow
    For Each C As Control In F.Controls
        My.Settings.ServicingLayout.AddControl(F.Name, C.Name, F.Controls.GetChildIndex(C))
    Next
End Sub

Private Event FoundFlow(ByVal F As FlowLayoutPanel)

Private Sub SaveFlowLayouts(ByVal CC As Object)
    For Each C As Control In CC
        If TypeOf C Is FlowLayoutPanel Then RaiseEvent FoundFlow(C)
        If C.Controls.Count > 0 Then SaveFlowLayouts(C.Controls)
    Next
End Sub

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:31:39+00:00Added an answer on June 9, 2026 at 8:31 pm

    Olivier is right in suggesting that LINQ is good for processing data through filters and applying transformations, etc… it doesn’t do other things (like recursion, multi-branch logic) so well.

    I was kind of able to do this in LINQ, but it is ugly.

    However, I would recommend stealing at least one LINQ feature… you can easily filter the ControlCollection for FlowLayoutPanel with this line (and as a bonus it’s already strongly typed for you!)

    Dim flowLayoutPanels = Me.Controls.OfType(Of FlowLayoutPanel)
    

    Without further-ado… ugly LINQ.

    Private Sub SaveWithLinq(ByVal CC As Control.ControlCollection)
      CC.OfType(Of FlowLayoutPanel).ToList.ForEach(
        Sub(f)
          f.Controls.Cast(Of Control).ToList.ForEach(
            Sub(c)
              My.Settings.ServicingLayout.AddControl(f.Name, c.Name,             
                                                     f.Controls.GetChildIndex(c))
            End Sub)
    
          If f.Controls.Count > 0 Then
            SaveWithLinq(f.Controls)
          End If
        End Sub)
    End Sub
    

    Part of the ugliness is due to the fact that Control.ControlCollection is not strongly typed (it implements IEnumerable instead of IEnumerable(Of T), so we have to tell LINQ the type of the objects in that collection (more detail here).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Couldn't remember better title, feel free to change it to something better :) My
(couldn't think of a better title, feel free to edit it to a title
Couldn't find a better place to ask this so I hope you guys can
Couldn't find a trace of the source code behind the Photos application that runs
Sorry couldn't think of a better title. :) Here goes, I have been pulling
i couldn't find in one place ,all the Appstore rules for the required images
Couldn't find anything relevant in forums So ,Please help me with this code .I'm
couldn't think of a better title. I just want someone to let me know
Couldn't Create Link Creating the link /usr/bin/mate failed with the following reason: Operation not
(couldn't think of a better title, sorry) So I've got my layout page, on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.