Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
251 views
in Technique[技术] by (71.8m points)

arrays - Put existing labels into list and change names based on list indices?

I have 22 labels. Half have DISCNumX and the other half have TOTNumX where X is a number 1 through 10, respectively. I've stored the values that the label text needs to be updated to in a list. I've also stored the names of the labels in a list. I was trying to iterate through each list, since they share the same index, and update the label.text to the value in the counts list.

Dim Counts As New List(Of Integer)
Dim DISCNumList As New List(Of Label)({NeedsCorrectionsDISCNum0, NotRecognizedDISCNum1, EPNErrorsDISCNum2, OptionHeadersDISCNum3, ProdPermsDISCNum4, ReadyToImportDISCNum5, WithMemosDISCNum6, RankWarningsDISCNum7, LifecycleWarningsDISCNum8})

Private Sub PopulateCounts()
    Dim i As Integer = 0
    InitializeComponent()
    For Each cont As Control In TableLayoutPanel1.Controls
        If cont.Name.Contains("DISCNum" & i.ToString) Then
            DISCNumList(i).Text = Counts(i)
            i += 1
        End If
    Next
End Sub

I've tried the above most recently, but I had been trying to do something as simple as this:

Private Sub PopulateCounts()
    InitializeComponent()
    For i = 0 To 10
        DISCNumList(i).Text = Counts(i)
    Next
End Sub

I would like to reiterate that the names of the labels in DISCNumList already exist on a form and I'm trying to update them. Any/all help here is greatly appreciated, as I have been able to get myself through a bunch of this stuff but am now properly stuck.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...