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
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;
3 Comments
Mohammad
you are absolutely welcome. please don't forgot to mark it as answer to help others. thanks.
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
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.