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

Click the column title(header) of GridView

9 Answers 119 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
kyle
Top achievements
Rank 1
kyle asked on 17 Nov 2010, 09:01 AM
Hi ,

I have a GridView,I want to handle the GotFocus event of it. When You click the GridViewCell or somewhere else,it will got focus.But When you click on the column's header(or title anyway), nothing happen.

RadControls for Silverlight Q2 2010 SP2
Microsoft Silverlight Version: 4.0.50917.0
Microsoft Visual Studio 2010 Version 10.0.30319.1 RTMRel
Microsoft .NET Framework Version 4.0.30319 RTMRel

My code as follows. Help me ,please!

GridViewDemo.xaml

<UserControl x:Class="DockingPane.GridViewDemo"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
     
    <Grid x:Name="LayoutRoot" Background="White">       
        <telerik:RadGridView x:Name="gridView">             
        </telerik:RadGridView>
    </Grid>
</UserControl>

GridViewDemo.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using System.Diagnostics;
 
namespace DockingPane
{
    public partial class GridViewDemo : UserControl
    {
        public GridViewDemo()
        {
            InitializeComponent();
            this.gridView.ItemsSource = EmployeeService.GetEmployees();
            this.gridView.GotFocus += new RoutedEventHandler(GridView_GotFocus);
        }
        public string Title = "GridViewDemo";
 
        private void GridView_GotFocus(object sender,RoutedEventArgs e)
        {
            UIElement element = e.OriginalSource as UIElement;
            Debug.WriteLine(element.ToString());
        }
    }
 
     
 
    public class Employee
    {
        public string FirstName
        {
            get;
            set;
        }
        public string LastName
        {
            get;
            set;
        }
        public int Age
        {
            get;
            set;
        }
        public bool Married
        {
            get;
            set;
        }
    }
 
    public class EmployeeService
    {
        public static ObservableCollection<Employee> GetEmployees()
        {
            ObservableCollection<Employee> employees = new ObservableCollection<Employee>();
            Employee employee = new Employee();
            employee.FirstName = "Maria";
            employee.LastName = "Anders";
            employee.Married = true;
            employee.Age = 24;
            employees.Add(employee);
            employee = new Employee();
            employee.FirstName = "Ana";
            employee.LastName = "Trujillo";
            employee.Married = true;
            employee.Age = 44;
            employees.Add(employee);
            employee = new Employee();
            employee.FirstName = "Antonio";
            employee.LastName = "Moreno";
            employee.Married = true;
            employee.Age = 33;
            employees.Add(employee);
            employee = new Employee();
            employee.FirstName = "Thomas";
            employee.LastName = "Hardy";
            employee.Married = false;
            employee.Age = 13;
            employees.Add(employee);
            employee = new Employee();
            employee.FirstName = "Hanna";
            employee.LastName = "Moos";
            employee.Married = false;
            employee.Age = 28;
            employees.Add(employee);
            employee = new Employee();
            employee.FirstName = "Frederique";
            employee.LastName = "Citeaux";
            employee.Married = true;
            employee.Age = 67;
            employees.Add(employee);
            employee = new Employee();
            employee.FirstName = "Martin";
            employee.LastName = "Sommer";
            employee.Married = false;
            employee.Age = 22;
            employees.Add(employee);
            employee = new Employee();
            employee.FirstName = "Laurence";
            employee.LastName = "Lebihan";
            employee.Married = false;
            employee.Age = 32;
            employees.Add(employee);
            employee = new Employee();
            employee.FirstName = "Elizabeth";
            employee.LastName = "Lincoln";
            employee.Married = false;
            employee.Age = 9;
            employees.Add(employee);
            employee = new Employee();
            employee.FirstName = "Victoria";
            employee.LastName = "Ashworth";
            employee.Married = true;
            employee.Age = 29;
            employees.Add(employee);
            return employees;
        }
    }
}

9 Answers, 1 is accepted

Sort by
0
kyle
Top achievements
Rank 1
answered on 18 Nov 2010, 03:26 AM
Hi,

GotFocus event is a bubbing event, so if i handle GotFocus event for GridView,everything in the GridView got focus should make the GridView onfocus.But why when i click on the column header it not work? I handle it like this:
this.gridView.GotFocus += new RoutedEventHandler(GridView_GotFocus);
seems click the column header can't trigger this event.
0
Veselin Vasilev
Telerik team
answered on 18 Nov 2010, 04:50 PM
Hi kyle,

I have just tried this with the latest binaries (Q3 2010) and the event fires when I click on the column header.
Can you try with this version please?

All the best,
Veselin Vasilev
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
kyle
Top achievements
Rank 1
answered on 19 Nov 2010, 07:07 AM
Yes,I've tried with the last version.But it still not work.My code just as above. Do i have some mistake?
0
Veselin Vasilev
Telerik team
answered on 24 Nov 2010, 04:51 PM
Hello kyle,

Please try this project and let me know what happens.

Kind regards,
Veselin Vasilev
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
kyle
Top achievements
Rank 1
answered on 29 Nov 2010, 03:44 AM
Seems same as mine. The first time you click the column's header,it's will output "Telerik.Windows.Controls.RadGridView",but i add a button (or something else),you click the button,it's output "Telerik.Windows.Controls.RadGridView" as well.And i set a breakpoint in the Debug.writeline line,then click the header,it can't trigger this.
0
Veselin Vasilev
Telerik team
answered on 01 Dec 2010, 05:33 PM
Hi kyle,

Can you please tell us the ultimate goal so we can provide some alternatives?

Thanks

Best wishes,
Veselin Vasilev
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
kyle
Top achievements
Rank 1
answered on 02 Dec 2010, 04:07 AM
Hi,

OK.Seems I should describe more clearly about my problem.Sorry for that. Assuming we have a page with some controls,for example,we have two GridViews named grid1 and grid2,and we also have a TextBox.When we click one of the GridView,it got focus and the TextBox will display  the name of it,grid1 or grid2.But now when we click on the column's header,it's belongs the GridView,but nothing happen.Do you got me?

BR
Kyle
0
Accepted
Veselin Vasilev
Telerik team
answered on 07 Dec 2010, 01:21 PM
Hello kyle,

You are right. It seems when you click on the column header - the sorting mechanism fires and prevents the gridview focus. What you can do is to subscribe to the Sorting event and perform the same logic (as with GotFocus) there.

Hope this is feasible for you.

Regards,
Veselin Vasilev
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
kyle
Top achievements
Rank 1
answered on 07 Dec 2010, 04:00 PM
Hi,

Oh yeah,that a good solution.Thanks!

BR
Kyle
Tags
GridView
Asked by
kyle
Top achievements
Rank 1
Answers by
kyle
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Share this question
or