views:

233

answers:

7

I need to be able to plot events on a vertical timeline and I like the way Google Calendar achieves this:

Screenshot of a day in Google Calendar

Currently I'm displaying the information with a ListView component, but this two practical drawbacks:

  1. It's far from clear when there's a gap
  2. Or, conversely, when there's an overlap

Both problems stem from the lack of representation of event length. This is the primary thing I'd like to rectify.

Is there a component available that will help me to do this? Else, does anyone have any suggestions for how I should go about making it from scratch?

I'm using C# and winforms.

+2  A: 

My first thoughts are to A) try using the Microsoft Charts to make this or B) Create a custom control that draws out rectangles for each event, and position the rectangle in the appropriate time range.

Tony Abrams
Tony - i must be very lazy, my 1st thought with this kind of thing is to see if there's a commercial supported component already out there - blush!! :)
jim
@jim, And there is nothing wrong with that. I just find that making the stuff usual ends up taking just as long as integrating/implementing 3rd party stuff :P
Tony Abrams
Hi Tony. I've put a bounty on this question. If Charts is the way forward, could you show me specifically how I'd go forward with this? Thanks.
Tom Wright
A: 

I have code that will produce output in a day view calendar format like you are wanting. unfortunately I can't just give it to you. but here is the gist:

  1. Create a container div, set it to the height you want, with overflow set to scroll
  2. Create an inner div, relative positioning, set to 50 * 24 pixels height
  3. Create 24 divs inside that, absolutly positioned, set a height of 50 and a top of 50 * i
  4. In each of the 24 divs, create divs for each tic mark at 25%, 50%, 75% and 100%
  5. To add an event:
    • Get the start hour, min, sec and * by 50 for the top
    • (Get the end hour, min, sec - start hour, min, sec) * 50 for the height

You could do the whole thing based on % but i ran into rounding issue in x-browser related stuff. As for events being next to each other, that was a "fun" algorithm to figure out.

Justin808
Thanks for the suggestion, but I'm not in a browser. My app is a winforms (desktop) application.
Tom Wright
Sorry i missed that when i first read the question. I image the concept would still be valid just using forms controls rather than web controls.
Justin808
+3  A: 

Tom, if you are ready to pay for commercial scheduling component, here is the one and similarly there are some others available in the market.

http://www.syncfusion.com/products/user-interface-edition/windows-forms/Schedule

but if you intend to develop one by yourself, then probably you could customize DataGrid control that's by far the reliable way which I could think of. but authoring a new windows forms control will take quite a bit of time, then we could expect.

Happy Coding.

Karthik
+1 for ready made component, but -10 for customizing a DataGrid for this purpose. I tried once, and that was a trip I'll never forget.
Daniel Mošmondor
+1  A: 

You will probably have to create a custom control having only the functionality for letting the user resize. And one layout manager to handle the resize events and arranging the custom controls. You just need to make sure that the smaller control is always on the top of the bigger control so that user has a chance to resize it.

ivymike
+1  A: 

Well, let's talk. I have several such controls behind me, so maybe I can help the issues involved.

  1. determine what is the smallest slot that you want to display on the screen - say 15 minutes
  2. divide your viewing area into slots of that duration - if you need to display 6 hours, create an list of 4x6=24 items
  3. each item will be the list of schedule objects found in there
  4. iterate your scheduling objects, and assign them to the list.
  5. iterate the list and draw. you should have enough information for a display like above.

    class ScheduleItem { DateTime start; DateTime end; string someText; }

    class OneSlot { list< ScheduleItem > ItemsInSlot; }

    list< OneSlot > VisibleSlots;

If you need pixel precision (you really don't need second precision here because you are on the screen not moving in time) you make slot as small as you have to here.

8 hours are 28800 seconds; if you have your time slot set to 30 seconds, you'll have 960 time slots available for mapping to the screen.

Hope it helps, comment me if your need to further discuss this.

Daniel Mošmondor
I have a hard time formatting my code block here... help
Daniel Mošmondor
Interesting question about the smallest slot. It'll probably be 30 minutes, but each item may not start on a 30 minute interval - the start and end times need to precise to the nearest second. (To do a code block, indent by four space, or use backticks for short snippets.)
Tom Wright
i did indent, but no help there. OK, you really don't want to be precise to the second... Let's say that you have 8 hours to display and height of 1000 pixels. Each pixel there is 8*60*60/1000 seconds, right? So, each pixel is 28,8 seconds, make it 30 seconds, divide 8 hours into 8*60*60/30=960 slots and there you go.
Daniel Mošmondor
+2  A: 

The best component I know for that is the devexpress scheduler control:

http://www.devexpress.com/Products/NET/Controls/WinForms/Scheduler/

jmservera
A: 

Another commercial offering: http://www.telerik.com/products/winforms/scheduler.aspx

Vladimir Alexiev