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

LoadedEvent for GridViewCell

2 Answers 39 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Andreas
Top achievements
Rank 1
Andreas asked on 22 Mar 2012, 04:00 PM

Hello,

in my Table-Control which is based on the RadGridView I'm trying to set an AttachedDependencyProperty for each GridViewCell.
My Problem is that I reached my Handler only for Rows of the Type CheckBoxColumn and ComboBoxColumn.

public class Table : RadGridView
{
    public Table()
    {
        EventManager.RegisterClassHandler(typeof(GridViewCellBase), LoadedEvent, new RoutedEventHandler(OnGridViewCellLoaded), true);
    }
     
    private static void OnGridViewCellLoaded(object sender, RoutedEventArgs e)
    {
        var cell = sender as GridViewCellBase;
        if (cell != null)
        {
            var dataType = cell.DataColumn.DataType;
            if (dataType == typeof(int) || dataType == typeof(double) || dataType == typeof(float) || dataType == typeof(decimal))
            {
                cell.SetValue(Table.NumberColumnProperty, true);
            }
        }
    }
     
    public static bool GetNumberColumn(DependencyObject obj)
    {
       return (bool)obj.GetValue(NumberColumnProperty);
    }
 
    public static void SetNumberColumn(DependencyObject obj, bool value)
    {
        obj.SetValue(NumberColumnProperty, value);
    }
 
    public static readonly DependencyProperty NumberColumnProperty =
            DependencyProperty.RegisterAttached("NumberColumn", typeof(bool), typeof(Table),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits));
 
}
 

2 Answers, 1 is accepted

Sort by
0
Accepted
Nedyalko Nikolov
Telerik team
answered on 26 Mar 2012, 12:39 PM
Hello,

Generally Loaded event routed strategy is "Direct", so you cannot use such syntax depending on "GridViewCellBase" class. However even with GridViewCell class used in EventManager.RegisterClassHandler method loaded event is not fired. I've added an event handler for Loaded event, and then ClassHandler delegate is invoked. I cannot add Loaded event handler just to support this case (which according to me is a framework issue) since this could lead to some memory leaks. I could suggest you to use dedicated RadGridView.CellLoaded event instead.
Let me know if there is something unclear or using RadGridView.CellLoaded event does not help.

Regards,
Nedyalko Nikolov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Andreas
Top achievements
Rank 1
answered on 26 Mar 2012, 01:01 PM

Hello,
thank you for your answer. Using the RadGridView.CellLoaded Event works very well for me.
thanks Andreas
Tags
GridView
Asked by
Andreas
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
Andreas
Top achievements
Rank 1
Share this question
or