CalendarItem move itself after a mouse click

Jun 28, 2010 at 3:01 PM
Hi all, I noticed that if I click with the mouse on a CalendarItem, the item move itself down when the mouse click is done on the bottom area of the item. Any idea why ? Cheers. warxsg
Jun 28, 2010 at 8:07 PM

I'm not sure what you mean.

But it sounds like you're saying the Item is dragging when it shouldn't be.

Regardless, I couldn't reproduce it on my machine. Can you provide more details? possibly screenshots?

Jun 28, 2010 at 9:31 PM

Hi BillyDRRyan,

 

thank you for your reply....the steps are :

 

1) Create a new item on your calendar

2) the item must have a startdate at 09:00 and an anddate at 12:00

3) Click on a point inside the item near the bottom border...near the 12:00

 

You will notice the movement...

If you have a suggestion to solve the problem..please let me it know.

Cheers.

warxsg

 

 

 

 

 

 

Jun 29, 2010 at 12:09 AM

thanks for clarifying.

I agree this seems to be a bug.
It happens when you have an item that spans over 1 tick of the calendar time scale; probably 30 minutes in your version of the demo app: for example: if the time scale is 30 minutes, and your item is 1 hour long.
You then must click in a timescale unit other than the first and hold. Example: with the time units you privided 9 - 12, if the time scale is 30 minutes then you can click in any of the units 9:30 to 12:00 on the item.
Then start to drag, or move the mouse, while holding the mouse button. You can even just move it a few pixels to the right or left.
The item will now jump to start at the unit you clicked in. Example: 9-12, with 30 min time scale. Click in the 9:30, move slightly and the item now starts at 9:30 and runs to 12:30.

 

it seems to be caused by the bolded line below from OnMouseMove(MouseEventArgs e) in Calendar.cs:

                    case CalendarState.DraggingItem:
                        TimeSpan duration = itemOnState.Duration;
                        itemOnState.SetIsDragging(true);
                        itemOnState.StartDate = hitted.Date;
                        itemOnState.EndDate = itemOnState.StartDate.Add(duration);
                        Renderer.PerformItemsLayout();
                        Invalidate();
                        itemOnStateChanged = true;
                        break;

Rather than automatically move the start date to hitted.Date it should track the original hitted.Date, store the offset from that to the original StartDate and always subtract that difference from the hitted.Date when assigning to the StartDate. You must make sure to clear this stored offset when releasing the mouse though.

 

I'll play with it when I get a chance, but I probably wont have time until tomorrow. Feel free to have a stab at it yourself though. 

Jun 29, 2010 at 11:39 AM
Hi BillyDRRyan, thank you for your reply....great support. I'll try to fix the problem. If you'll find a good solution, please let me know. Cheers. warxsg
Jun 29, 2010 at 4:26 PM

I uploaded a Patch that fixes this issue; it is kind of a hack, but it should work.

you can get it at http://bettercalendar.codeplex.com/SourceControl/PatchList.aspx patch ID 6222

 

There are better ways to fix this, but this was fast. I didn't test much for repercussions, so let me know if you find any.

Jun 29, 2010 at 7:38 PM

Hi BillyDRyan,

thank you very much for the path.....great support !

I'll try it and I'll let you know if it's ok.

Cheers.

 

             warxsg

Jun 29, 2010 at 7:59 PM

Hi BillyDRyan,

I tested your path and I found a little bug and, probably a fix in "Calendar.cs"

After the lines :

DRAG_OFFSET = DRAG_OFFSET_SET ? DRAG_OFFSET : hitted.Date.TimeOfDay - itemOnState.StartDate.TimeOfDay;                        

DRAG_OFFSET_SET = true;

You should add the following code :

if (DRAG_OFFSET.TotalMinutes > 0)

 newStartDate = newStartDate.Subtract(DRAG_OFFSET);

In this way the newStarDate doesn't change and the CalendarItem doesn't move itself.

I hope that this fix works...anyway....you helped me a lot.

Cheers.

            warxsg