Fixed button height when autosizerows = True

1 Answer 56 Views
GridView
Todd
Top achievements
Rank 1
Todd asked on 04 Apr 2023, 01:39 PM

Hello,

I have a RadGridView with AutoSizeRows=True.  The last column is a GridViewCommandColumn.   The issue is that I would like the height of the "buttons" in the last column to all be the same height and not vary by row height.  In the example image below, I would like all buttons to be the same height as the button in the first row.

How I would I achieve this?

Thanks,
Todd

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 05 Apr 2023, 11:39 AM

Hi, Todd,

When the AutoSizeRows property is enabled, the rows' height depend on the content it stores. The GridCommandCellElement internally hosts a RadButtonElement that is stretched to fill the content.If you need to make the button element with fixed height, it is suitable to handle the CellFormatting event and disable the vertical stretching for the button:

        public RadForm1()
        {
            InitializeComponent();
            this.radGridView1.AutoSizeRows = true;

            GridViewCommandColumn commandColumn = new GridViewCommandColumn();
            commandColumn.Name = "CommandColumn";
            commandColumn.UseDefaultText = false;
            commandColumn.FieldName = "ProductName"; 
          
            radGridView1.MasterTemplate.Columns.Add(commandColumn);
            foreach (GridViewDataColumn col in this.radGridView1.Columns)
            {
                col.WrapText = true;
            }

            this.radGridView1.CellFormatting += radGridView1_CellFormatting;
        }

        private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
        {
            GridCommandCellElement buttonCell = e.CellElement as GridCommandCellElement;
            if (buttonCell != null)
            {
                buttonCell.CommandButton.StretchVertically = false;
            }
        }

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

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Todd
Top achievements
Rank 1
commented on 05 Apr 2023, 03:02 PM

Hi Dess,

This worked perfectly.!

Thank you so much!
Todd

Tags
GridView
Asked by
Todd
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or