Selection event

Hi,

is it possible  to intercept the selection event of the gantt chart?

And is it possible to select the row of the task in  the gantt chart modifing the style?

Best regards
Gian Piero 

9 Replies 1 reply marked as answer

SS Sridevi Sivakumar Syncfusion Team March 24, 2021 02:35 PM UTC

Hi Gian Piero Truccolo,

is it possible  to intercept the selection event of the gantt chart?

We have checked the reported query and we do not have direct support to meet your requirements. So we have achieved your requirement by using CollectionChanged event as per the below code snippet.

CollectionChanged  event will be triggered when we select the item form Gantt

Code snippet:
 
[C#]: 
    public partial class MainWindow : Window 
    { 
         public MainWindow() 
        { 
            InitializeComponent(); 
            Gantt.SelectedItems.CollectionChanged += SelectedItems_CollectionChanged; 
  
        } 
        private void SelectedItems_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) 
        { 
        
        } 
    } 

[XAML]: 
   <sync:GanttControl x:Name="Gantt" ItemsSource="{Binding TaskCollection}" 
                           VisualStyle="Metro" > 
           <sync:GanttControl.TaskAttributeMapping> 
                <sync:TaskAttributeMapping  TaskIdMapping="TaskId" 
                                            TaskNameMapping="TaskName" 
                                            StartDateMapping="StartDate" 
                                            ChildMapping="Child"                                             
                                            FinishDateMapping="FinishDate" 
                                            DurationMapping="Duration" 
                                            MileStoneMapping="IsMileStone" 
                                            ProgressMapping="Progress" 
                                            PredecessorMapping="Predecessor"/> 
            </sync:GanttControl.TaskAttributeMapping> 
        </sync:GanttControl> 

is it possible to select the row of the task in  the gantt chart modifing the style?

In Gantt control, we don't have support for customizing the selected row. 

Please refer the below link to add the style for all nodes.

https://help.syncfusion.com/wpf/gantt/custom-node-style

Let us know if you need any further assistance.

Regards,
Sridevi S.
 


Marked as answer

GI Gian March 24, 2021 03:56 PM UTC

Hi,

is it possible only to select one task in gantt chart?

Best regards
Gian Piero Truccolo


SS Sridevi Sivakumar Syncfusion Team March 25, 2021 10:10 AM UTC

Hi Gian Piero Truccolo,

We have analyzed your requirement and you can achieve it by setting ListBoxSelectionMode as One as per the below code snippet.

[XAML]: 
  <sync:GanttControl x:Name="Gantt" Loaded="Gantt_Loaded" 
                           ItemsSource="{Binding TaskCollection}" 
                           VisualStyle="Metro"  > 
... 
        </sync:GanttControl> 

[C#]: 
    public partial class MainWindow : Window 
    { 
         public MainWindow() 
        { 
            InitializeComponent(); 
            Gantt.SelectedItems.CollectionChanged += SelectedItems_CollectionChanged; 
  
        } 
        private void SelectedItems_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) 
        { 
        } 
  
        private void Gantt_Loaded(object sender, RoutedEventArgs e) 
        { 
            this.Gantt.GanttGrid.Model.Options.ListBoxSelectionMode = Syncfusion.Windows.Controls.Grid.GridSelectionMode.One; 
        } 
    } 

Let us know if you need any further assistance.

Regards,
Sridevi S.
 



GI Gian March 25, 2021 10:32 AM UTC

Hi,

my goal is to select more then one task in GanttChart.
Not one.

Can i select in Gantt chart more then one task?

I dont' use gantt grid, it is hide.

Best regards
Gian Piero Truccolo




ET Eswaran Thirugnanasambandam Syncfusion Team March 25, 2021 07:39 PM UTC

Hi Gian Piero Truccolo, 
 
We have analyzed your requirement and we have achieved it by adding the selected item task to the HighlightedItems collection as per below code snippet.  
 
[XAML]: 
 
   <sync:GanttControl x:Name="Gantt" HighlightedItems="{Binding HighlightedTasks}" GridWidth="0" 
                           ItemsSource="{Binding TaskCollection}" 
                           VisualStyle="Metro" 
                            > 
 ... 
        </sync:GanttControl> 
 
[C#]: 
 
    public partial class MainWindow : Window 
 
    { 
 ... 
        private void SelectedItems_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) 
        { 
            if (this.Gantt.SelectedItems != null && this.Gantt.SelectedItems.Count != 0) 
            { 
                var selectedItem = this.Gantt.SelectedItems[0] as TaskDetails; 
               var highlightedTask = (this.DataContext as ViewModel).HighlightedTasks;          
  
              if (highlightedTask.Count>0 && highlightedTask.Contains(selectedItem)) 
                { 
                    //If you again clicked the selected item, it will get reset here 
                    highlightedTask.Remove(selectedItem); 
                } 
                else 
                { 
                    highlightedTask.Add(selectedItem); 
                } 
            } 
        } 
    } 
 
Screenshot: 
 
 
 
 
For more information about highlighting a task 
 
 Let us know if you need any further assistance. 
 
Regards, 
Eswaran. 



GI Gian March 26, 2021 11:33 AM UTC

Hi,

is it possible also by user with the mouse select more tasks bars, for example with Ctrl + left Click button.

Best regards
Gian Piero Truccolo


VR Vignesh Ramesh Syncfusion Team March 29, 2021 12:26 PM UTC

Hi Gian Piero Truccolo, 

Thanks for your update. 

We would like to inform that you can be able to perform the multiple selection in our previously provided sample by simply clicking the nodes one by one (No need to press Ctrl key). 

Regards, 
Vignesh Ramesh. 



GI Gian April 9, 2021 12:19 PM UTC

Hi,

we have to implement the MouseBinding command Ctrl + LeftClick.

I hhve tried to do this  by adding this in xaml

<syncfusion:GanttControl.InputBindings>
                            <MouseBinding Gesture="Ctrl+LeftClick" Command="{Binding CtrlCheckedCommand}"/>
</syncfusion:GanttControl.InputBindings>

But the command is not called, so is there a way to implement that?
Or have i missed something?

Best regards
Gian Piero Truccolo


VR Vignesh Ramesh Syncfusion Team April 13, 2021 06:25 PM UTC

Hi Gian Piero Truccolo, 

We have analyzed your query and achieved your requirement using PreviewMouseLeftButtonDown event, SelectedItems and HighlightedItems properties of GanttControl. Please find the snippet below 

XAML: 
<sync:GanttControl x:Name="Gantt" 
                   HighlightedItems="{Binding HighlightedTasks}" 
                   ItemsSource="{Binding TaskCollection}" 
                    
                   PreviewMouseLeftButtonDown="Gantt_PreviewMouseLeftButtonDown"> 
 
</sync:GanttControl> 
 

C#: 
private void Gantt_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) 
{ 
    Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(UpdateSelectedItem)); 
} 
 
 
private void UpdateSelectedItem() 
{ 
    var highlightedTasks = (this.DataContext as ViewModel).HighlightedTasks; 
    if (this.Gantt.SelectedItems != null && this.Gantt.SelectedItems.Count != 0) 
    { 
        var selectedItem = this.Gantt.SelectedItems[0] as TaskDetails; 
        if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) 
        { 
            if (highlightedTasks.Count > 0 && highlightedTasks.Contains(selectedItem)) 
            { 
                // If click on the already selected item, then unselected it. 
                highlightedTasks.Remove(selectedItem); 
            } 
            else 
            { 
                // Select multiple items. 
                highlightedTasks.Add(selectedItem); 
            } 
        } 
        else 
        { 
            // If cntrl key is not pressed, then clear the old, selected items and select current item. 
            highlightedTasks.Clear(); 
            highlightedTasks.Add(selectedItem); 
        } 
    } 
    else 
    { 
        // Clear the selected items when click on the same element. 
        highlightedTasks.Clear(); 
    } 
} 
 


Now you can be able to select the multiple items from Gantt Chart using Ctrl+left click. Please find the sample from the below link 


We hope it helps you. 

Regards, 
Vignesh Ramesh. 


Loader.
Up arrow icon