Loading combobox with time

G

Guest

Hi,

I would like to load time in a dropdown similar to the outlook calendar
appointment time dropdown.

Here is how I do this:

comboboxTimer.Items.Add( (object) "12:00 AM" );
comboboxTimer.Items.Add( (object) "12:30 AM" );
for(int i=1; i<=11; i++)
{
comboboxTimer.Items.Add( (object)( i.ToString() + ":00 AM") );
comboboxTimer.Items.Add( (object)( i.ToString() + ":30 AM") );
}
comboboxTimer.Items.Add( (object) "12:00 PM" );
comboboxTimer.Items.Add( (object) "12:30 PM" );
for(int i=1; i<=11; i++)
{
comboboxTimer.Items.Add( (object)( i.ToString() + ":00 PM") );
comboboxTimer.Items.Add( (object)( i.ToString() + ":30 PM") );
}

The simplest way I could think of for now. Okay now I use this on 2 combo
boxes. THe first one is a start time and the later the end time. On the
SelectedIndexChanged event of the start time I do the followinig:

private void DateStartTime_SelectedIndexChanged(object sender,
System.EventArgs e) {
//DateStartTime.OnLoad(this.DateStartTime.SelectedValue.ToString(),
this.DateEndTime.SelectedValue.ToString());
DateTime start;
DateTime end;
start = Convert.ToDateTime(DateStartTime.SelectedValue);
end = start.AddMinutes(30);
this.DateEndTime.SelectedValue = end.ToShortTimeString();
}

All works find. I would like to add an extra feature I could not come up
with a solution yet and perhaps you can help me out here. I would like to add
the minutes and hours difference between start and end times respectively. I
would like it concatenated with my end time dropdown... Exactly like when you
use the new appoinmtent for from Outlook.

Any suggestions or ideas?

Thanks,

Yama
 
G

Guest

Yama said:
Hi,

I would like to load time in a dropdown similar to the outlook calendar
appointment time dropdown.

Here is how I do this:

comboboxTimer.Items.Add( (object) "12:00 AM" );
comboboxTimer.Items.Add( (object) "12:30 AM" );
for(int i=1; i<=11; i++)
{
comboboxTimer.Items.Add( (object)( i.ToString() + ":00 AM") );
comboboxTimer.Items.Add( (object)( i.ToString() + ":30 AM") );
}
comboboxTimer.Items.Add( (object) "12:00 PM" );
comboboxTimer.Items.Add( (object) "12:30 PM" );
for(int i=1; i<=11; i++)
{
comboboxTimer.Items.Add( (object)( i.ToString() + ":00 PM") );
comboboxTimer.Items.Add( (object)( i.ToString() + ":30 PM") );
}

The simplest way I could think of for now. Okay now I use this on 2 combo
boxes. THe first one is a start time and the later the end time. On the
SelectedIndexChanged event of the start time I do the followinig:

private void DateStartTime_SelectedIndexChanged(object sender,
System.EventArgs e) {
//DateStartTime.OnLoad(this.DateStartTime.SelectedValue.ToString(),
this.DateEndTime.SelectedValue.ToString());
DateTime start;
DateTime end;
start = Convert.ToDateTime(DateStartTime.SelectedValue);
end = start.AddMinutes(30);
this.DateEndTime.SelectedValue = end.ToShortTimeString();
}

All works find. I would like to add an extra feature I could not come up
with a solution yet and perhaps you can help me out here. I would like to add
the minutes and hours difference between start and end times respectively. I
would like it concatenated with my end time dropdown... Exactly like when you
use the new appoinmtent for from Outlook.

Any suggestions or ideas?

Thanks,

Yama
 
G

Guest

Hi
U can use Data lIst as dat source and can change on Selected index changes
or Set Combo Box text as Concatenated text (loaded on selected index changed)
and access actual time by querying value of combo box

Regards
Tarun
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top