Click here to Skip to main content
15,883,870 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

How to make a combobox showing the current index or current value or current text to the next 30 minutes just like outlook selecting time for new meeting? I have a fix combobox collection starting 12:00 AM, 12:30 AM, 1:00 AM to 11:30 PM like full day time.

Where combo box "Start Time" by default is nearest next 30 minutes.

- If the PC time is 9:35 AM, it will automatically select to 10:00 AM.
- If the PC time is 10:00AM, it will automatically select to 10:30 AM.

As picture from below link
http://www.ljmu.ac.uk/ITHelp/ITHelp_Images/OutlookNewAppointment.png[^]

Edited
** I need a link to code this on combobox

TQ
Posted
Comments
Trung Nguyen Son 11-Aug-14 1:58am    
Have you tried my solution, yet?
Luiey Ichigo 13-Aug-14 21:45pm    
yeah man..awesome!

C#
// It's a function for rounding up or down by a minute interval
public static DateTime Round(DateTime dt, int dir, int interval)
{
	// dir 1 = up, dir 0 = down
	DateTime t;
	if (dir == 1)
		t = dt.AddMinutes((60 - dt.Minute) % interval);
	else
		t = dt.AddMinutes(-dt.Minute % interval);
	return t;
}


For the StartTime, you will use:

C#
DateTime startTime = Round(Now, 1, 30);


For the second combobox, you will use:

C#
DateTime nextTime = startTime.AddMinutes(30);
 
Share this answer
 
v5
Comments
Luiey Ichigo 13-Aug-14 21:45pm    
Thanks man..it's work!!!! Great
this might help you..


DateTime.AddMinutes[^]
 
Share this answer
 
Comments
Luiey Ichigo 11-Aug-14 0:22am    
I can't see the idea :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900