Question about RadHostItem.MinSize

1 Answer 64 Views
Panel RibbonBar
Adriana Lorena
Top achievements
Rank 1
Adriana Lorena asked on 12 Jul 2022, 05:21 PM

Hello everyone,

I'm learning to use Telerik for winforms, but I have an issue with RadHostItem that hosts a Windows TableLayoutPanel that is generated at runtime and the RadHostItem is placed inside a RadDropDownButtonElement on a RibbonBar.

I'm using  RadHostItem.MinSize for the host that contains the TableLayoutPanel but I've tried a lot of ways to size the host height but neither of them is working as desired.

In what units RadHostItem.MinSize is defined?

For example, I have this code:

                Telerik.WinControls.RadHostItem radHost = new Telerik.WinControls.RadHostItem(panel);
                int heightPerRow = panel.GetRowHeights()[0]; // Height of a row in pixels,
                radHost.MinSize = new Size(panel.Width, heightPerRow * headerRow);

                radDropDownButton.Items.Add(radHost);

But this host is very big for the panel and it distorts it.

I'll appreciate any help.

Thanks in advance,

Adriana

 

 

 

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 14 Jul 2022, 09:01 AM
Hello, Adriana, 

The RadHostItem.MinSize property expects a Size value specifying the width/height in pixels. I have prepared a sample project for your reference:
        public RadForm1()
        {
            InitializeComponent();
            TableLayoutPanel panel = new TableLayoutPanel();
            SetupTableLayoutPanel(panel);
            Telerik.WinControls.RadHostItem radHost = new Telerik.WinControls.RadHostItem(panel);
            int heightPerRow = panel.GetRowHeights()[0];  
            radHost.MinSize = new Size(panel.Width, heightPerRow * panel.RowCount);
            this.radDropDownButtonElement1.Items.Add(radHost);
        }

        private void SetupTableLayoutPanel(TableLayoutPanel panel)
        { 
            panel.ColumnCount = 3;
            panel.RowCount = 1;
            panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 40F));
            panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 30F));
            panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 30F));
            panel.RowStyles.Add(new RowStyle(SizeType.Absolute, 50F));
            panel.Controls.Add(new Label() { Text = "Address" }, 0, 0);
            panel.Controls.Add(new Label() { Text = "Contact No" }, 1, 0);
            panel.Controls.Add(new Label() { Text = "Email ID" }, 2, 0);
             
            panel.RowCount = panel.RowCount + 1; 
            panel.Controls.Add(new Label() { Text = "Street, City, State" }, 0, panel.RowCount - 1);
            panel.Controls.Add(new Label() { Text = "888888888888" }, 1, panel.RowCount - 1);
            panel.Controls.Add(new Label() { Text = "xxxxxxx@gmail.com" }, 2, panel.RowCount - 1);
        }

Please give it a try and see how it works on your end.

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

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Adriana Lorena
Top achievements
Rank 1
commented on 14 Jul 2022, 01:43 PM

Hello Dess,

Hope you're fine. Thank you for the guidance. The code you sent me works ok with the first two rows but if I add about 10 rows, the host gets very large (see attached image radDropDownButtonWith10rows.jpg)

This is the code I'm using to populate the tablelayoutpanel:

        private void SetupTableLayoutPanel(TableLayoutPanel panel)
        {
            panel.ColumnCount = 3;
            panel.RowCount = 1;
            panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 40F));
            panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 30F));
            panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 30F));
            panel.RowStyles.Add(new RowStyle(SizeType.Absolute, 50F));
            for (int i = 0; i < 10; i++)
            {
                panel.Controls.Add(new Label() { Text = "Address" + i }, 0, panel.RowCount - 1);
                panel.Controls.Add(new Label() { Text = "Contact No" + i }, 1, panel.RowCount - 1);
                panel.Controls.Add(new Label() { Text = "Email ID" + i }, 2, panel.RowCount - 1);
                panel.RowCount = panel.RowCount + 1;
            }

        }

How can I adjust the size of the host to it's content?

Thanks in advance,

Adriana

Dess | Tech Support Engineer, Principal
Telerik team
commented on 18 Jul 2022, 05:21 AM

Hello, Adriana, 

The header row's height seems to be 50px returned by the TableLayoutPanel.GetRowHeights method. However, the height for the rest of the rows in the TableLayoutPanel is 23px. That is why when setting the MinSize for the RadHostItem I would suggest you to use the height for the data rows:

 

        public RadForm1()
        {
            InitializeComponent();
            TableLayoutPanel panel = new TableLayoutPanel();
            SetupTableLayoutPanel(panel);
            Telerik.WinControls.RadHostItem radHost = new Telerik.WinControls.RadHostItem(panel);
            int headerHeight = panel.GetRowHeights()[0];
            int heightPerRow = panel.GetRowHeights()[1];
            radHost.MinSize = new Size(panel.Width, headerHeight + heightPerRow * (panel.RowCount - 1));
            this.radDropDownButtonElement1.Items.Add(radHost);
        }

        private void SetupTableLayoutPanel(TableLayoutPanel panel)
        {
            panel.ColumnCount = 3;
            panel.RowCount = 1;
            panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 40F));
            panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 30F));
            panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 30F));
            panel.RowStyles.Add(new RowStyle(SizeType.Absolute, 50F));
            panel.Controls.Add(new Label() { Text = "Address" }, 0, 0);
            panel.Controls.Add(new Label() { Text = "Contact No" }, 1, 0);
            panel.Controls.Add(new Label() { Text = "Email ID" }, 2, 0);

            for (int i = 0; i < 10; i++)
            {
                panel.Controls.Add(new Label() { Text = "Address" + i }, 0, panel.RowCount - 1);
                panel.Controls.Add(new Label() { Text = "Contact No" + i }, 1, panel.RowCount - 1);
                panel.Controls.Add(new Label() { Text = "Email ID" + i }, 2, panel.RowCount - 1);
                panel.RowCount = panel.RowCount + 1;
            }
        }

 

Tags
Panel RibbonBar
Asked by
Adriana Lorena
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or