Sorry, but I still dont get it, from that image, there is nothing to see what are 30 min, 45 min, 50 min and 1 hour.
Please, now DO a decent explanation what this numbers mean, and where they are located EXACTLY.

Otherwise I cannot help you at all.

Edited 4 Years Ago by Mitja Bonca: chaged text

for example when i select 6am as first the start time, the end time will have the items 6:30 am, 6:45 am, 6:50 am and 7:00 am
and that is working. my problemnow is when i select second start time

this is my code for the start time:

CbEnd.Items.Clear()
CbEnd.Items.Add(Date.Parse(CbStart.Text).AddMinutes(45).ToString("hh:mm tt"))
CbEnd.Items.Add(Date.Parse(CbStart.Text).AddMinutes(50).ToString("hh:mm tt"))
CbEnd.Items.Add(Date.Parse(CbStart.Text).AddMinutes(60).ToString("hh:mm tt"))

this is my code for the end time:

CbStart.Items.Add(ComboBox5.SelectedItem.ToString)
CbStart.Items.Add(Date.Parse(CbEnd.Text).AddMinutes(45).ToString("hh:mm tt"))
CbStart.Items.Add(Date.Parse(CbEnd.Text).AddMinutes(50).ToString("hh:mm tt"))
CbStart.Items.Add(Date.Parse(CbEnd.Text).AddMinutes(60).ToString("hh:mm tt"))

when i add

CbStart.Items.Clear()

in end time it clears the combobox and i can't save anything in my database coz it keeps clearing but when i don't add

CbStart.Items.Clear()

the items that had already been selected is still there which makes the user to select a wrong time...hope its clear and hope anyone will help me with this...sorry again for the trouble

So you have in start comboBox only full hours? Like 6am, 7am, 8am, ...
and in 2nd comboBox then 4 items with selected hour + 30, 45, 50minutes and next full hour?
Am I get this?

EXAMPLE:
So 1st combo: 6am, 7am, 8am, 9am,...
When selection 7am 2nd combo has:
7.30am, 7.45am, 7.50am, 8am

Is this it?

and when the user select in combobox2 7:45 combobox1 will have items 7:45 and 7:15

No, not at all. Seriously. I am affraid I cannot help you with this kind of explanation. Until you do it better.
I simply dont understand what do you want to do...

I have read all the posts in this thread ones again carefully, and try to understand what you wanna do.
Let me go through with steps the user will go:
PS: A is comboBoxStart, B is comboBoxEnd OK? To make is shorter

  1. 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)

... and so on
Am I right?

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

Edited 4 Years Ago by Jx_Man

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.

@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

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.

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

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

Edited 4 Years Ago by Mitja Bonca: changed dode

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?

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

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

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

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

Edited 4 Years Ago by jhedonghae

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.

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

This article has been dead for over six months. Start a new discussion instead.