Click here to Skip to main content
15,888,984 members

Flow layout panel with user controls - how to get at user control values?

Aero72 asked:

Open original thread
Dear all,

I hope I'm not about to poperly fall at the final fence - hopefully someone can point me in the right direction...I have a flow layout panel into which I'm putting many instances of a user control. This control (for now) just has a check box and a few text fields only.

The code in the user control form looks like:
C#
public partial class myfrmList : UserControl
{
    public int Index
    {
        get { return int.Parse(lb_Ref.Text); }
        set { lb_Ref.Text = value.ToString(); }
    }
    public CheckState Displayed
    {
        get { return cb_show.CheckState; }
        set { cb_show.CheckState = value; }
    }
...etc you get the idea...
}

In the code for my main form, when I want to put a new instance of the user control into the flow layout panel, I can do this with...

C#
myflowlayoutpanel.Controls.Add(new myfrmList
{
    Displayed = CheckBoxState,
    Index = Indexval
});

...and the flow layout panel is populated with a new instance of my user control with the values I've set in it.

My problem is I can't find the right syntax to be able to use the 'get' routines to return values from each instance of the user control. I can iterate through the controls inside the flow control panel..e.g....

C#
for (ctr = 0; ctr < myflowlayoutpanel.Controls.Count; ctr++)
{
    foreach (Control c in myflowlayoutpanel.Controls[ctr].Controls)
    {
        c....

    }
}


but if I do that it looks like all I can do is get the collection of controls in the user control - not their values.

I hope I'm just missing something obvious....if so I'm sorry for bothering you...

Many Thanks,

Aero
Tags: C#, User Controls

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900