0

I have list of arrays of labels and I want to change visibility of some label in some array in list by index. Tell me, please, how can I do that?

3 Answers 3

0

is this what you want:

    foreach (var l in list)
        if (l.Name.Equals("test", StringComparison.OrdinalIgnoreCase))
            l.Visible = false;

or:

    foreach (var l in list)
        if (l.TabIndex == 1)
            l.Visible = false;
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you! This is exactly what I needed.
you are absolutely welcome. please don't forgot to mark it as answer to help others. thanks.
Of course, I just needed to wait a few minutes before accepting the answer.
0

You said you want to change visibility of your labels with indexes. So something like that:

List<Label[]> labels;//your labels 

Label[] firstArray=labels[0];
Label[] secondArray=labels[1];
...

Label firstLabelInFirstArray=firstArray[0]; //get first label
Label secondLabelInFirstArray=firstArray[1]; //get second label

firstLabelInFirstArray.Visible=true; //In Windows Forms
firstLabelInFirstArray.Visibility=Visibility.Hidden; //In WPF

Comments

0

You can just access the specific label on your array location like you would access other variables in an array:

Label[] labels = new Label[10];
labels[0] = new Label();
labels[0].Text = "blablabla";
labels[0].Visible = true;
...
labels[9] = new Label();
labels[9].Text = "blablabla";
labels[9].Visible = false;
...

Of course the same goes for a List, etc.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.