This is a migrated thread and some comments may be shown as answers.

Can I trigger a cell_clicked event?

1 Answer 67 Views
GridView
This is a migrated thread and some comments may be shown as answers.
zai yunfeng
Top achievements
Rank 2
zai yunfeng asked on 17 Sep 2009, 05:34 AM
hi.
Can I trigger a cell_clicked event?Should I use MouseDown event instead?
I have another question about gridview.
When I select a row in gridview, is there any way to unselect this row only use a mouse? There is a control called ListCtrl in Visual C++. You can cancel a selection by click on blank area.

Thanks a lot.

1 Answer, 1 is accepted

Sort by
0
Accepted
Milan
Telerik team
answered on 17 Sep 2009, 09:06 AM
Hi zai yunfeng,

You could trigger any type of event in WPF. For example, this will trigger MouseLeftButtonDown event:

MouseButtonEventArgs args = new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Left);  
args.RoutedEvent = FrameworkElement.MouseLeftButtonDownEvent;  
this.RaiseEvent(args); 

The currently available selection modes do not allow deselection with the mouse only but you can easily implement that feature:

public partial class Window1 : Window  
{  
    public Window1()  
    {  
        InitializeComponent();  
        this.myGrid.AddHandler(FrameworkElement.PreviewMouseLeftButtonDownEvent,  
            new RoutedEventHandler(this.OnMouseUp) ,true);  
    }  
 
    private void OnMouseUp(object sender, RoutedEventArgs args)  
    {  
        FrameworkElement originalSource = args.OriginalSource as FrameworkElement;  
        GridViewRow row = originalSource.ParentOfType<GridViewRow>();  
 
        if (row != null && row.IsSelected)  
        {  
            row.IsSelected = false;  
            args.Handled = true;  
        }  
    }  




Regards,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
zai yunfeng
Top achievements
Rank 2
Answers by
Milan
Telerik team
Share this question
or