Click Event on Gantt Chart

Hi,

i create a context menu on the gantt chart that i show after the right click of the mouse.
I woulk like to hide the first menu if i don't click any Task, is it possible?


Best regards
Gian Piero Truccolo

1 Reply 1 reply marked as answer

SS Sridevi Sivakumar Syncfusion Team April 1, 2021 02:54 PM UTC

Hi v Gian Piero Truccolo,

Greetings from Syncfusion.

We have checked the reported query and we have achieved as per below


The context menu for a selected node will display by using the Gantt control SelectedItems CollectionChanged, as shown in the following code snippet:

Code snippet [C#]:
 
        public MainWindow() 
        { 
            InitializeComponent(); 
 
            this.Gantt.SelectedItems.CollectionChanged += SelectedItems_CollectionChanged; 
        } 
 
        private void SelectedItems_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) 
        { 
            if (e.Action == NotifyCollectionChangedAction.Add) 
            { 
                contextMenu.Items.Clear(); 
                contextMenu.Items.Add(new MenuItem() { Header = "Node pressed" }); 
                contextMenu.Items.Add(new MenuItem() { Header = "Node pressed" }); 
            } 
        } 

The context menu for the Gantt chart  will display by using the Gantt control MouseRightButtonDown event, as shown in the following code snippet:

Code snippet [XAML]:
 
  <sync:GanttControl x:Name="Gantt"   GridWidth="0"  MouseRightButtonDown="Gantt_MouseRightButtonDown" 
                               ItemsSource="{Binding TaskCollection}" 
                               UseAutoUpdateHierarchy="False" 
                                VisualStyle="Metro"> 
... 
        <sync:GanttControl.ContextMenu> 
            <ContextMenu x:Name="contextMenu" BorderBrush="Black" BorderThickness="1" > 
            </ContextMenu> 
        </sync:GanttControl.ContextMenu> 
        </sync:GanttControl> 
    

[C#]: 
       private void Gantt_MouseRightButtonDown(object sender, MouseButtonEventArgs e) 
        { 
            contextMenu.Items.Clear(); 
            contextMenu.Items.Add(new MenuItem() { Header = "Chart pressed" }); 
        } 

Let us know if you need any further assistance.

Regards,
Sridevi S.
 


Marked as answer
Loader.
Up arrow icon