0

I can get the value of a single control that has been created at run time, that control is a DateTimePicker, but i can't get the values of multiple controls. how do i do it?

code:

This is where i add the DateTimePicker with every click at run time.

Private Sub btnAddTime_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddTime.Click
    Dim Time As New DateTimePicker()
    Dim count As Integer = GroupBox1.Controls.OfType(Of DateTimePicker)().ToList().Count
    Time.Location = New Point(9, (23 * count) + 22)
    Time.Size = New Size(150, 20)
    Time.Format = DateTimePickerFormat.Time
    Time.ShowUpDown = True
    Time.Name = "DateTimePicker" & (count + 1)
    GroupBox1.Controls.Add(Time)
End Sub

And this is where i get the values of the controls.

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Dim i As Integer = 0
    For Each cntrl In Form3.GroupBox1.Controls
        Dim dt As DateTimePicker = Form3.GroupBox1.Controls.Item("DateTimePicker" & (i + 1))
        If DateTime.Now.ToString = dt.Value Then
            MsgBox("P")
        End If
    Next
End Sub

I can only get the the value of a created control if only i specified it in the code, i think i can't get the right Name of the control. I'm trying to make the program to read every value of the control in another form while the Timer ticks. help?

2
  • Why can't you read dt.Name within your For Each loop? Commented Mar 11, 2016 at 8:10
  • uhm tips on how to do that please? Commented Mar 11, 2016 at 8:15

1 Answer 1

3

Try this:

    For Each cntrl In Form3.GroupBox1.Controls
        If TypeOf cntrl Is DateTimePicker Then
            If DateTime.Now.ToString = cntrl.Value Then
                MsgBox("P")
            End If
        End If
    Next
Sign up to request clarification or add additional context in comments.

4 Comments

or instead, use For Each cntrol In Form3.GroupBox1.Controls.OfType(Of DateTimePicker)() so you won't need to use If TypeOf....
Thanks a lot! Master! m(_ _;)m
No problem pre. Hehe
pde pla tagalog dito hehe, Salamats idol!

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.