We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

InLine Elements - get the selected one

Hi Everyone,
i was checking the demo example of the gantt with inline elements.
I didn't found how to get the selected inline element; found the way to get the selected line (with the list of the inline elements) but i need to get the single inline element selected.

let me know

thanks!!

3 Replies

RA Rachel A Syncfusion Team December 30, 2019 01:03 PM UTC

Hi Mirko, 
 
Greetings from Syncfusion. 
 
GanttControl does not have direct support to get the selected inline item. So, we have achieved your requirement by hooking PreviewMouseLeftButtonDown event for GanttChart and get the selected inline item from DataContext of its e.OriginalSource argument value. Please find the snippet from below 
 
[C#]: 
 
public MainWindow() 
{ 
    InitializeComponent(); 
    Gantt.Loaded += Gantt_Loaded; 
} 
 
private void Gantt_Loaded(object sender, RoutedEventArgs e) 
{ 
    GanttChart chart = this.Gantt.FindElementOfType<GanttChart>(); 
    chart.PreviewMouseLeftButtonDown += Chart_PreviewMouseLeftButtonDown; 
} 
 
private void Chart_PreviewMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) 
{ 
    Border border = e.OriginalSource as Border; 
    if (border != null && border.DataContext is Item) 
    { 
        // You can get the selected inline item from its dataContext as like below. 
        Item selectedInLineItem = border.DataContext as Item; 
    } 
} 
 
 
Please find the sample from the below link 
 
Regards, 
Rachel. 



MC Mirko Costadoni December 31, 2019 04:39 PM UTC

that's good!
i've added some lines to the Chart_PreviewMouseLeftButtonDown event cause it works only if you click on the specific border.

            Item selectedInLineItem = null;
            Border border = e.OriginalSource as Border;
            if (border != null && border.DataContext is Item)
            {
                selectedInLineItem = border.DataContext as Item;
            }
            if (selectedInLineItem == null)
            {
                Grid grid = e.OriginalSource as Grid;
                if (grid != null && grid.DataContext is Item)
                {
                    selectedInLineItem = grid.DataContext as Item;
                }
            }


RA Rachel A Syncfusion Team January 2, 2020 10:39 AM UTC

Hi Mirko, 
 
We would like to inform that, in our previous update, we have provided workaround to get the inline item’s instance while click on it by using GanttChart’s PreviewMouseLeftButtonDown event.  
 
We have updated the sample which is provided in our previous update with the provided snippet and checked the reported problem by select anywhere in the inline item. We afraid we are not able to reproduce the reported problem. Can you please check with the tested sample and video in the following location? 
 
 
 
If still you are facing the problem, please revert us by modifying the sample based on your application along with replication steps like short video and configuration details, etc. This would be helpful for us to give better solution in this. 
 
We have checked with the below configuration 
 
Visual Studio Version: 2019, V16.3.3 
Windows Version: 1903 
Syncfusion Version: 17.4.0.40 
 
Note: The selection of the inline items is done by clicking on the node. 
 
Regards, 
Rachel. 


Loader.
Live Chat Icon For mobile
Up arrow icon