Custom Cells in GridView and Event Handlers

2 posts, 0 answers
  1. CHRISTIAN
    CHRISTIAN avatar
    39 posts
    Member since:
    Nov 2010

    Posted 14 Apr 2014 Link to this post

    Hello,

    I have to fix an existing GridView where some events are created to often. This occours only when scrolling in the grid.
    The "CreateCellElement" Method is getting called several times and thus the events are being created too often.

            public override FrameworkElement CreateCellElement(GridViewCell cell, object dataItem)
            {
                  ... some code....

                  var lookup = new CustomCell(cell, dataItem, var, var2);

                  cell.MouseLeftButtonDown += lookup.OnMouseLeftButtonDown;
                  cell.KeyDown += lookup.OnKeyDown;
                  cell.KeyUp += lookup.OnKeyUp;

                return lookup;
            }

    This happens when "EnableColumnVirtualization"  and "EnableRowVirtualization" is set to true.
    Well, i cant set them to false because the grid is allready too slow.

    First i tried to delete the events with "-=" on "Unload" but that doesn´t work.

    How can i prevent that the events getting attached?

    Regards

  2. Yoan
    Admin
    Yoan avatar
    1066 posts

    Posted 17 Apr 2014 Link to this post

    Hello,

    When the virtualization of RadGridView is turned on, its elements are created when they should be brought into view and they are also reused on scrolling (i.e. the rows/cells are recreated on scrolling). Thus, it is not recommended to work with the visual elements (i.e. GridViewRow/GridViewCell) and their properties. You can take a look at the UI Virtualization help article for a reference. 

    Regards,
    Yoan
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. DevCraft banner
Back to Top