|
| 1 | +--- |
| 2 | +title: Disabling Task Resizing in RadGanttView for WinForms |
| 3 | +description: Learn how to disable the resizing of tasks in RadGanttView while still allowing drag and drop operations. |
| 4 | +type: how-to |
| 5 | +page_title: How to Disable Resizing of Tasks in RadGanttView for WinForms |
| 6 | +slug: ganttview-disable-resizing |
| 7 | +tags: ganttview, winforms, resize, dragdrop, custom behavior |
| 8 | +res_type: kb |
| 9 | +ticketid: 1550947 |
| 10 | +--- |
| 11 | + |
| 12 | +## Environment |
| 13 | + |
| 14 | +|Product Version|Product|Author| |
| 15 | +|----|----|----| |
| 16 | +|2024.3.806|RadGridView for WinForms|[Dinko Krastev](https://www.telerik.com/blogs/author/dinko-krastev)| |
| 17 | + |
| 18 | +## Description |
| 19 | + |
| 20 | +In some scenarios, you might want to prevent users from resizing tasks in the RadGanttView component but still allow them to move tasks to a different time. This KB article details how to disable only the resizing functionality of tasks in RadGanttView, ensuring users cannot alter the task duration but can move them. |
| 21 | + |
| 22 | +## Solution |
| 23 | + |
| 24 | +To achieve the desired behavior, you can create a custom `GanttViewBehavior` and override the `ProcessMouseMoveWhenResizingTask()` method. By not calling the base implementation of this method, you effectively prevent the task resizing action. However, other functionalities, such as drag and drop of tasks, remain unaffected. Follow the steps below to implement the custom behavior: |
| 25 | + |
| 26 | +Here is the implementation of the custom `GanttViewBehavior`: |
| 27 | + |
| 28 | +````C# |
| 29 | +public class CustomGanttViewBehavior: BaseGanttViewBehavior |
| 30 | +{ |
| 31 | + protected override void ProcessMouseMoveWhenResizingTask(GanttGraphicalViewBaseTaskElement element, MouseEventArgs e) |
| 32 | + { |
| 33 | + // Prevent the base logic from executing to disable resizing |
| 34 | + // base.ProcessMouseMoveWhenResizingTask(element, e); |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +```` |
| 39 | + |
| 40 | +To apply this custom behavior to your RadGanttView, set the `GanttViewElement.GanttViewBehavior` property to an instance of your custom behavior class: |
| 41 | + |
| 42 | +````C# |
| 43 | +SGanttView.GanttViewElement.GanttViewBehavior = new CustomGanttViewBehavior(); |
| 44 | + |
| 45 | +```` |
| 46 | +What's left is to change the cursor to its default look when the mouse is over the edge of the item. This can be done in the __CursorChanged__ event handler of the control: |
| 47 | + |
| 48 | +````C# |
| 49 | +private void radGanttView1_CursorChanged(object sender, EventArgs e) |
| 50 | +{ |
| 51 | + if (this.radGanttView1.Cursor == Cursors.SizeWE) |
| 52 | + { |
| 53 | + this.radGanttView1.Cursor = Cursors.Default; |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +```` |
| 58 | + |
| 59 | +By applying this solution, users will be able to move tasks without being able to resize them, ensuring the tasks' duration remains unchanged. |
| 60 | + |
| 61 | +## See Also |
| 62 | + |
| 63 | +- [RadGanttView Input Behavior Documentation](https://docs.telerik.com/devtools/winforms/controls/ganttview/input-behavior) |
| 64 | +- [RadGanttView Overview](https://docs.telerik.com/devtools/winforms/controls/ganttview/overview) |
0 commit comments