1.11M Members

time interval

 
0
 

After 39 posts, I think mitja explain more detail and easy to understand than OP. :)

 
0
 

Jx, can you understand what does he want? I think you cannot - not from this kind of explanation.
I did an example code from what I think he wants, but the problem is he wants something different every time he makes a new post.
I the last of them, there was 15 minutes included too, which havent been before.

 
0
 

@Mitja this is right
PS: A is comboBoxStart, B is comboBoxEnd OK? To make is shorter

A has 6am (B has now 6.30am, 6.45am, 6.50am, 7am)
2.1. example1: user selects from A (6am), and from B(6.30am)
2.2. this means in A must be now 6.30am only (and in B 6.45am, 6.50am, 7am)

3.1. example2: user selects from A (6am), and from B (7am)
3.2. this means in B is now 7am, (and in B 7.30am, 7.45am, 7.50am, 8am)

@Jx sorry if i'm not able to explain it well

 
1
 

Finally we agree.
Here is the solution that works - as we came to the concludion:

Public Partial Class Form1
    Inherits Form
    Public Sub New()
        InitializeComponent()
        comboBox1.Items.Add("6:00 am")
    End Sub

    Private Sub comboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
        Dim times As List(Of DateTime) = Data_Combo2(comboBox1.SelectedItem.ToString())
        comboBox2.Text = ""
        comboBox2.Items.Clear()
        For Each time As DateTime In times
            comboBox2.Items.Add(time.ToString("t"))
        Next
    End Sub

    Private Sub comboBox2_SelectedIndexChanged(sender As Object, e As EventArgs)
        Dim time As DateTime = Data_Combo1(comboBox2.SelectedItem.ToString())
        comboBox1.Text = ""
        comboBox1.Items.Clear()
        comboBox1.Items.Add(time.ToString("t"))
    End Sub

    Private Function Data_Combo1(input As String) As DateTime
        Dim time As DateTime = DateTime.Parse(input, System.Globalization.CultureInfo.InvariantCulture)
        Return time
    End Function

    Private Function Data_Combo2(input As String) As List(Of DateTime)
        Dim time As DateTime = DateTime.Parse(input, System.Globalization.CultureInfo.InvariantCulture)
        Dim list As New List(Of DateTime)()
        Select Case time.Minute
            Case 0
                If True Then
                    list.Add(time.AddMinutes(30))
                    list.Add(time.AddMinutes(45))
                    list.Add(time.AddMinutes(50))
                    list.Add(time.AddMinutes(60))
                    Exit Select
                End If
            Case 30
                If True Then
                    list.Add(time.AddMinutes(15))
                    list.Add(time.AddMinutes(20))
                    list.Add(time.AddMinutes(30))
                    Exit Select
                End If
            Case 45
                If True Then
                    list.Add(time.AddMinutes(5))
                    list.Add(time.AddMinutes(15))
                    Exit Select
                End If
            Case 50
                If True Then
                    list.Add(time.AddMinutes(10))
                    Exit Select
                End If
        End Select
        Return list
    End Function

End Class

Let me know how its gonna work.

 
0
 

that works..thank you for the effort...but their is a problem...when i select 6am in combobox1 and select 7am in combobox2, combobox1 clears and vise versa in which i can't save anything

 
1
 

Just remove or comment this line: comboBox1.Text = "" from comboBox2_SelectedIndexChanged events.
Change to:

   Private Sub comboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
    Dim times As List(Of DateTime) = Data_Combo2(comboBox1.SelectedItem.ToString())
    comboBox2.Text = ""
    comboBox2.Items.Clear()
    For Each time As DateTime In times
        comboBox2.Items.Add(time.ToString("t"))
    Next
End Sub

Private Sub comboBox2_SelectedIndexChanged(sender As Object, e As EventArgs)
    Dim time As DateTime = Data_Combo1(comboBox2.SelectedItem.ToString())
    'comboBox1.Text = "";  remove or comment this line

    comboBox1.Items.Clear()
    comboBox1.Items.Add(time.ToString("t"))
End Sub
 
0
 

now you could vote some +1.
after such a hard work :)

 
0
 

but is this possible:
when user select in combobox1 6am and in combobox2 7am
and when for the second start time combobox1 will only have items such as 7am and don't have the 6am to avoid wrong selection???? is it clear?

 
0
 

Sure, use this

Private Sub comboBox2_SelectedIndexChanged(sender As Object, e As EventArgs)
    Dim time As DateTime = Data_Combo1(comboBox2.SelectedItem.ToString())
    comboBox1.Items.Clear()
    comboBox1.Text = comboBox2.SelectedItem.ToString() 'put this line of code!
    comboBox1.Items.Add(time.ToString("t"))
End Sub
 
0
 

vote + comment :)

 
0
 

it doesn't work...here is what i mean i hope its clear
A has 6am (B has now 6.30am, 6.45am, 6.50am, 7am)
first start time: user selects from A (6am), and from B(6:30am)
second start time: 6am must not appear in A it must only have 6:30am so that user will not be able to select 6am again, from B(7:30am)
third start time: 6:30am must not also appear in A and must only have 7:30 and so on

 
0
 

This is exactly how my code now works. I mean exactly. When user does a selection in B, this time immediatelly appears in A (literaly, when used does a selection in B, this same value appears in A).
So this is what you want to. And thisis how my code works.
I will remove ones again what I have added in last change. So it should be like:

Private Sub comboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
    Dim times As List(Of DateTime) = Data_Combo2(comboBox1.SelectedItem.ToString())
    comboBox2.Text = ""
    comboBox2.Items.Clear()
    For Each time As DateTime In times
        comboBox2.Items.Add(time.ToString("t"))
    Next
End Sub

Private Sub comboBox2_SelectedIndexChanged(sender As Object, e As EventArgs)
    Dim time As DateTime = Data_Combo1(comboBox2.SelectedItem.ToString())
    comboBox1.Items.Clear()
    comboBox1.Items.Add(time.ToString("t"))
End Sub

READ CAREFULLY:
Now you can select A (6.00am) and then select B (7.00am).
A still has the same selected value (even if there is a new value bellow TextBox - but you cannot see it yet, since you didnt do a pick).
Next - IMPORTANT: When you click on A again, there is still 6.00am inside a textBox, but in a drop down list is now available new value - 7.00AM).
If you will select it the textBox will get new value 7.00am, if you will not select it, 6.00am will remain.
IMPORTNT: As soon as you will choose a new value from A (so 7.00am), the B will get new values.

This is it. I cannot think of a better logic.

Hope it helps,
bye

 
0
 

well when i select in combobox1, combobox2 will indeed have items but when i select items in combobox2, combobox1 will be cleared so i can't save anything....but by the way tnx for the help

 
0
 

When you select an item from comboBox2, comboBox1 items will be cleared yes (but there will still be an item in a textBox of combobox). This is how it goes.
You wanted this kind of code.

 
2
 

After 53 replies people are not understanding ur problem. why dont u post it in more details and well documented way?

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article