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

How to add MouseLeftButtonDownEvent to TreeListView's Cell

5 Answers 51 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Minwei
Top achievements
Rank 1
Minwei asked on 25 Jan 2011, 02:07 PM
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





5 Answers, 1 is accepted

Sort by
0
Minwei
Top achievements
Rank 1
answered on 25 Jan 2011, 02:30 PM
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.

0
Vanya Pavlova
Telerik team
answered on 25 Jan 2011, 05:42 PM
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>>
0
Minwei
Top achievements
Rank 1
answered on 26 Jan 2011, 02:48 AM
We have read the thread.
Is there any other way to solve this issue?

Thx.
0
Maya
Telerik team
answered on 26 Jan 2011, 08:38 AM
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>>
0
Minwei
Top achievements
Rank 1
answered on 27 Jan 2011, 07:27 AM
Thanks for your help.
We'll have a try.


Tags
TreeListView
Asked by
Minwei
Top achievements
Rank 1
Answers by
Minwei
Top achievements
Rank 1
Vanya Pavlova
Telerik team
Maya
Telerik team
Share this question
or