button in first header cell

7 posts, 0 answers
  1. Hans
    Hans avatar
    15 posts
    Member since:
    Nov 2010

    Posted 03 Sep 2014 Link to this post

    How can I place a button in the first header cell above the row selection arrows?  I would like to do this in a class derived from gridview.

    Hans Heuvelman
  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3952 posts

    Posted 08 Sep 2014 Link to this post

    Hello Hans,

    Thank you for writing.

    You can place a RadButtonElement in the current row's header cell above the row selection arrow by creating a custom GridRowHeaderCellElement. Our GridView >> Creating custom cells help article is quite useful on this topic. Here is a sample code snippet demonstrating the approach for achieving your goal:
     
    public Form1()
    {
        InitializeComponent();
        this.radGridView1.TableElement.RowHeight = 30;
    }
     
    private void radGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e)
    {
        if (e.CellType == typeof(GridRowHeaderCellElement))
        {
            e.CellElement = new CustomGridRowHeaderCellElement(e.Column, e.Row);
        }
    }
     
    public class CustomGridRowHeaderCellElement : GridRowHeaderCellElement
    {
        RadButtonElement btn;
        LightVisualElement imageElement;
     
        public RadButtonElement Button
        {
            get
            {
                return btn;
            }
        }
     
        public LightVisualElement ImageElement
        {
            get
            {
                return this.imageElement;
            }
        }
     
        public CustomGridRowHeaderCellElement(GridViewColumn column, GridRowElement row) : base(column, row)
        {
        }
     
        protected override Type ThemeEffectiveType    
        {
            get   
            {
                return typeof(GridRowHeaderCellElement);    
            }
        }
     
        protected override void CreateChildElements()
        {
            base.CreateChildElements();
            this.Children.RemoveAt(0);
     
            DockLayoutPanel panel = new DockLayoutPanel();
     
            btn = new RadButtonElement();
            btn.MinSize = new Size(15, 10);
            DockLayoutPanel.SetDock(btn, Telerik.WinControls.Layouts.Dock.Top);
         
            panel.Children.Add(btn);
             
            imageElement = new LightVisualElement();
            imageElement.Margin = new System.Windows.Forms.Padding(0, 0, 0, 2);
            panel.Children.Add(imageElement);  
            DockLayoutPanel.SetDock(imageElement, Telerik.WinControls.Layouts.Dock.Bottom);
            this.Children.Add(panel);
        }
    }
     
    private void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
    {
        CustomGridRowHeaderCellElement cell = e.CellElement as CustomGridRowHeaderCellElement;
        if (cell != null)
        {
            cell.ImageElement.Image = cell.Image;
            cell.Image = null;
            if (cell.RowInfo.IsCurrent)
            {
                cell.Button.Visibility = Telerik.WinControls.ElementVisibility.Visible;
            }
            else
            {
                cell.Button.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
            }
        }
    }

    I hope this information helps. Should you have further questions, I would be glad to help.

    Regards,
    Desislava
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. Hans
    Hans avatar
    15 posts
    Member since:
    Nov 2010

    Posted 08 Sep 2014 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Unforunately the buttom appears in the first cell of the datarows in stead of the first headercell left of 'column1'.

  4. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3952 posts

    Posted 08 Sep 2014 Link to this post

    Hello Hans,

    Thank you for writing back.

    On my end the button appears correctly in the row header cell above the arrow image indicating the current row. I have attached my sample project.

    If you have any additional questions, please let me know.

    Regards,
    Desislava
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  5. Hans
    Hans avatar
    15 posts
    Member since:
    Nov 2010

    Posted 09 Sep 2014 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    But I need the button in the first cell of header-row, the cell before header-cell 'ProductID'.  Not in the current row.
    See attached picture.
  6. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3952 posts

    Posted 11 Sep 2014 Link to this post

    Hello Hans,

    Thank you for writing back.

    The provided picture helped me to understand completely the exact requirement. Please find below the modified sample code demonstrating how to achieve the result from the attached screenshot:
    private void radGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e)
    {
        if (e.CellType == typeof(GridTableHeaderCellElement))
        {
            e.CellElement = new CustomGridRowHeaderCellElement(e.Column, e.Row);
        }
    }
     
    public class CustomGridRowHeaderCellElement : GridTableHeaderCellElement
    {
        RadButtonElement btn;
     
        public CustomGridRowHeaderCellElement(GridViewColumn column, GridRowElement row) : base(column, row)
        {
        }
     
        protected override Type ThemeEffectiveType
        {
            get
            {
                return typeof(GridTableHeaderCellElement);
            }
        }
     
        protected override void CreateChildElements()
        {
            base.CreateChildElements();
            this.Children.RemoveAt(0);
            btn = new RadButtonElement();
            btn.MinSize = new Size(15, 10);
            this.Children.Add(btn);
        }
    }

    I hope this information helps. If you have any additional questions, please let me know.
     
    Regards,
    Desislava
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  7. Hans
    Hans avatar
    15 posts
    Member since:
    Nov 2010

    Posted 12 Sep 2014 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    This is exactly what I was looking for.  Thanks a lot.
Back to Top