Missing RowHeaderColumn and ContextMenu throw an Exception on CustomNewRowInfo

5 posts, 1 answers
  1. Agung
    Agung avatar
    5 posts
    Member since:
    Sep 2016

    Posted 31 Jan Link to this post

    Hi...

    i got some problem on my custom new row element according to this link, but on my code i made with button element

    internal class CustomGridNewRowElement : GridRowElement
    {
        private GridCellElement cellElement;
        private RadButtonElement radButtonElement;
        public RadButtonElement AddButtton => this.radButtonElement;
     
        public CustomGridNewRowElement() { }
     
        protected override void CreateChildElements()
        {
            base.CreateChildElements();
            this.cellElement = new GridCellElement(null, this) { StretchHorizontally = true, StretchVertically = true };
            this.radButtonElement = new RadButtonElement("Add New");
            this.Children.Add(cellElement);
            this.cellElement.Children.Add(this.radButtonElement);
            this.cellElement.ClipDrawing = true;
        }
     
        public override bool IsCompatible(GridViewRowInfo data, object context)
        {
            return data is CustomGridViewRowInfo;
        }
    }
     
    internal class CustomGridViewRowInfo : GridViewNewRowInfo
    {
        public CustomGridViewRowInfo(GridViewInfo viewInfo) : base(viewInfo)
        {
        }
     
        public override Type RowElementType => typeof(CustomGridNewRowElement);
    }

    the problem is im missing an rowheadercellelement as shown on attachment, i need the Add Button only fit on GridViewDataColumns like a standard GridViewNewRowInfo,

    and shown on 2nd attachment it throw an exception when mouse right button press / contextmenu on Add Button Element, i couldnt find whats wrong.

    any help please.

     

  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3943 posts

    Posted 03 Feb Link to this post

    Hello, Agung,   

    Following the provided information, I have created a sample project. Indeed, when you right-click the RadButtonElement in the new row, an error occurs. This is because there is no ColumnInfo applied to the GridCellElement that hosts the button. 

    The possible solution that I can suggest is to create a custom GridCellElement and override its ShowContextMenu method. Comment the default logic and if you want to show a menu, feel free to create one: 

            internal class CustomGridNewRowElement : GridRowElement
            {
                private GridCellElement cellElement;
                private RadButtonElement radButtonElement; 
    
                public RadButtonElement MyProperty
                {
                    get
                    {
                        return this.radButtonElement;
                    }
                }
     
                public CustomGridNewRowElement()
                {
                }
     
                protected override void CreateChildElements()
                {
                    base.CreateChildElements();
                    this.cellElement = new CustomGridCellElement(null, this) { StretchHorizontally = true, StretchVertically = true };
                    this.radButtonElement = new RadButtonElement("Add New"); 
                    this.Children.Add(cellElement);
                    this.cellElement.Children.Add(this.radButtonElement);
                    this.cellElement.ClipDrawing = true;
                }
     
                public override bool IsCompatible(GridViewRowInfo data, object context)
                {
                    return data is CustomGridViewRowInfo;
                }
            }
    
            public class CustomGridCellElement : GridCellElement
            { 
                public CustomGridCellElement(GridViewColumn column, GridRowElement row) : base(column, row)
                {
                }
                protected override void ShowContextMenu()
                {
                    RadContextMenu menu = new RadContextMenu();
                    menu.Items.Add(new RadMenuItem("Item1"));
                    menu.Show(new Point(MousePosition.X,MousePosition.Y) ); 
                }
            }

     


    I hope this information helps. If you need any further assistance please don't hesitate to contact me.  

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Agung
    Agung avatar
    5 posts
    Member since:
    Sep 2016

    Posted 03 Feb in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Hi Dess, your code works perfect. Thank you

    One more thing, if it possible how RadButtonElement can fit in GridViewDataColumns only? i need the buttonelement fit on the blue rectangle, please check the attachment.

    how to manipulate the GridRowHeaderCellElement.

    im trying add GridRowHeaderCellElement with this code:

    protected override void CreateChildElements()
    {
        try
        {
            base.CreateChildElements();
            this.cellElement = new CustomGridCellElement(null, this) { StretchHorizontally = true, StretchVertically = true };
            this.AddButton = new RadButtonElement("Add New");
            this.Children.Add(new GridRowHeaderCellElement(null, this));
            this.Children.Add(cellElement);
            this.cellElement.Children.Add(this.AddButton);
            this.cellElement.ClipDrawing = true;
        }
        catch (Exception e)
        {
            throw e;
        }
    }

    but it throw Object reference not set to an instance of an object.

    at Telerik.WinControls.UI.GridVirtualizedCellElement.BindRowProperties()

    at Telerik.WinControls.UI.GridRowHeaderCellElement.BindRowProperties()
       at Telerik.WinControls.UI.GridVirtualizedCellElement.Initialize(GridViewColumn column, GridRowElement row)
       at Telerik.WinControls.UI.GridRowHeaderCellElement..ctor(GridViewColumn column, GridRowElement row)
       at CustomNewRow.CustomGridNewRowElement.CreateChildElements()

     the error i thing is cause the GridRowHeaderCellElement columninfo is null

    any help?

     

     

     

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

    Posted 04 Feb Link to this post

    Hello, Agung,   

    You can apply a left offset in the RadButtonElement.Margin property:

                protected override void CreateChildElements()
                {
                    base.CreateChildElements();
                    this.cellElement = new CustomGridCellElement(null, this) { StretchHorizontally = true, StretchVertically = true };
                    this.radButtonElement = new RadButtonElement("Add New"); 
                    this.Children.Add(cellElement);
                    this.radButtonElement.Margin = new Padding(20, 0, 0, 0);
                    this.cellElement.Children.Add(this.radButtonElement);
                    this.cellElement.ClipDrawing = true;
                }

     

    Should you have further questions please let me know.

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  5. Agung
    Agung avatar
    5 posts
    Member since:
    Sep 2016

    Posted 04 Feb Link to this post

    Hi Dess, that's not what I want. for sure the button element is move with padding, but I need to insert the RowHeaderCellElement like other rows or with the default GridViewNewRowInfo, at the moment i just set the ShowRowHeaderColumn Visible, Thank you
Back to Top