0

Firstly, i’m kinda new to programming with vb.net and this is only my second project (it’s for school)

So, here’s my problem

I’m trying to make a timetable using vb.net

So far, I’m done with the add and delete of user control

This is how i added new user control to the flow layout panel

If DomainUpDown1.Text = "Sunday" Then
        Dim I As New UserControl1
        I.Name = "test:" & _index
        I.Label8.Text = Label8.Text
        I.Label9.Text = Label9.Text
        I.Label10.Text = Label10.Text
        If Panel18.BackColor = Color.PowderBlue Then
            I.BackColor = Color.PowderBlue
        ElseIf Panel18.BackColor = Color.MistyRose Then
            I.BackColor = Color.MistyRose
        ElseIf Panel18.BackColor = Color.NavajoWhite Then
            I.BackColor = Color.NavajoWhite
        ElseIf Panel18.BackColor = Color.DarkSeaGreen Then
            I.BackColor = Color.DarkSeaGreen
        End If
        FlowLayoutPanel1.Controls.Add(I)
        _index += 1

but i’m not completely finished with the add. As you can see user can add new event at the same day and time of another event

What i want is that: if the user click save button to add new event(user control) BUT if there already exists another event in that day(flowLayoutPanel) and also at the same time An error message should appear.

But I can’t figure how that code gonna go. Hope you understood my problem.

Two events: same day and time:

enter image description here

Idle_Mind
  • 38,363
  • 3
  • 29
  • 40
H.S
  • 1
  • Have a read here: https://stackoverflow.com/questions/10516997/add-control-value-before-another-control-value-in-c-sharp – Andrew Mortimer Jan 27 '23 at 15:50
  • As written, you'd have to iterate over the UserControls in the FlowLayoutPanel and compare its Label8 value to that of the requested time in the corresponding setup Label8. This is a really bad design, which isn't surprising since you're new to programming. The correct approach would be to design a CLASS that represents an Event and give it fields with correct data types (DateTime for storing days/times, String for the event itself, etc.) so you can do proper comparisons and math with the values within. The UserControl is just a way to display the data, and shouldn't be the data store itself. – Idle_Mind Jan 27 '23 at 15:57
  • Also, you can change that entire If...Else block to just: `I.BackColor = Panel18.BackColor`. – Idle_Mind Jan 27 '23 at 15:59

0 Answers0