How to add MouseLeftButtonDownEvent to TreeListView's Cell

6 posts, 0 answers
  1. Minwei
    Minwei avatar
    31 posts
    Member since:
    Jul 2010

    Posted 25 Jan 2011 Link to this post

    We have occurred a problem in register TreeListView's cell.
    Code:
        this.RowLoaded += new EventHandler<RowLoadedEventArgs>(CustomTabTreeListView_RowLoaded);
        this.RowUnloaded += new EventHandler<RowUnloadedEventArgs>(CustomTabTreeListView_RowUnloaded);
    void CustomTabTreeListView_RowUnloaded(object sender, RowUnloadedEventArgs e)
    {
        TreeListViewRow row = e.Row as TreeListViewRow;
        if (row != null)
        {
            row.Cells.ToList().ForEach(t => t.RemoveHandler(GridViewCellBase.MouseLeftButtonDownEvent, new EventHandler<MouseButtonEventArgs>(CustomTabTreeListView_Cell_MouseLeftButtonDown)));
        }
    }
     
    void CustomTabTreeListView_RowLoaded(object sender, RowLoadedEventArgs e)
    {
        TreeListViewRow row = e.Row as TreeListViewRow;
        if (row != null)
        {
            row.Cells.ToList().ForEach(t => t.AddHandler(GridViewCellBase.MouseLeftButtonDownEvent, new EventHandler<MouseButtonEventArgs>(CustomTabTreeListView_Cell_MouseLeftButtonDown), true));
        }
    }
     
    private void CustomTabTreeListView_Cell_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
     
    }


    Exception occurred in row.Cells.ToList().ForEach(t => t.AddHandler(GridViewCellBase.MouseLeftButtonDownEvent, new EventHandler<MouseButtonEventArgs>(CustomTabTreeListView_Cell_MouseLeftButtonDown), true));
     
    Could you help me?
     
    Thanks





  2. Minwei
    Minwei avatar
    31 posts
    Member since:
    Jul 2010

    Posted 25 Jan 2011 Link to this post

    And if we changed to
                TreeListViewRow row = e.Row as TreeListViewRow;
                if (row != null)
                {
                    row.Cells.ToList().ForEach(t => t.MouseLeftButtonDown += CustomTabTreeListView_Cell_MouseLeftButtonDown);
                }

    The MouseLeftButtonDown event can't be triggered.

  3. DevCraft banner
  4. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 25 Jan 2011 Link to this post

    Hi Minwei,

     
    Have you defined CellTemplate in RadTreeListView's columns? If that is the case you may take a look at the following forum thread "Gridview cell click event" and you will understand how to fire this event in an appropriate manner.

    Kind regards,
    Vanya Pavlova
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  5. Minwei
    Minwei avatar
    31 posts
    Member since:
    Jul 2010

    Posted 25 Jan 2011 Link to this post

    We have read the thread.
    Is there any other way to solve this issue?

    Thx.
  6. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 26 Jan 2011 Link to this post

    Hi Minwei,

    Another approach would be to add a handler directly to the RadTreeListView and verify that you have a clicked on a cell:

    public MainPage()
    {
      InitializeComponent();       this.RadTreeListView1.AddHandler(GridViewCellBase.MouseLeftButtonDownEvent, new MouseButtonEventHandler(OnMouseLeftButtonDown), true);
    }
     
    private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
                var clickedElement = e.OriginalSource as FrameworkElement;
                if (clickedElement != null)
                {
                    var cell = clickedElement.ParentOfType<GridViewCell>();
                    if(cell != null)
                    {
                        MessageBox.Show("You clicked on a cell");
                    }
                }      
    }  
     

    All the best,
    Maya
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  7. Minwei
    Minwei avatar
    31 posts
    Member since:
    Jul 2010

    Posted 27 Jan 2011 Link to this post

    Thanks for your help.
    We'll have a try.


Back to Top
DevCraft banner