Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15516

VS 2017 Flowlayoutpanel index out of range when using TabControl

$
0
0
OK - sorry, I tried to google this, but not sure what to google. And wasn't sure how to word it in the Title either.
the listFlDay is a List(of FlowLayoutPanel)
Code:

  Private Sub AddLabelDayToFlDay(ByVal startDayAtFlNumber As Integer, ByVal totalDaysInMonth As Integer)
        For Each fl As FlowLayoutPanel In listFlDay
            fl.Controls.Clear()
            fl.Tag = 0

            fl.BackColor = Color.LightGray

        Next
        Dim myMargin = New Padding
        myMargin.All = 0



        For i As Integer = 1 To totalDaysInMonth
            Dim lbl As New Label
            lbl.Name = $"lblDay{i}"
            lbl.AutoSize = False
            lbl.TextAlign = ContentAlignment.TopLeft
            lbl.Margin = myMargin
            lbl.Text = i
            lbl.Font = New Font("Neo Sans", 14)
            listFlDay((i - 1) + (startDayAtFlNumber - 1)).Tag = i
            listFlDay((i - 1) + (startDayAtFlNumber - 1)).Controls.Add(lbl)
            flDays.SetFlowBreak(lbl, True)
            lbl.BackColor = Color.White
            If lbl.BackColor = Color.White Then
                listFlDay((i - 1) + (startDayAtFlNumber - 1)).BackColor = Color.White
            End If
            If New Date(currentDate.Year, currentDate.Month, i) = Date.Today Then
                listFlDay((i - 1) + (startDayAtFlNumber - 1)).BackColor = Color.DimGray
                lbl.BackColor = Color.DimGray
            End If


        Next

    End Sub

This code works fine if it's in it's own form, but I'm trying to put it on a TabControl and now I am getting Index was out of range. Must be non-negative and less than the size of the collection.
Debugging it says listFlDay Count = 0 System.Collections.Generic.List(Of System.Windows.Forms.FlowLayoutPanel)
Everything else is giving the correct numbers.
Do I need to put TabControl in front of something? Or should I just put it back on it's own form and load that on the Tab? Any ideas - Thanks

Viewing all articles
Browse latest Browse all 15516

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>