This is a migrated thread and some comments may be shown as answers.

Auto Grid Resizing

1 Answer 185 Views
MultiColumn ComboBox
This is a migrated thread and some comments may be shown as answers.
Ben
Top achievements
Rank 1
Ben asked on 12 Apr 2013, 12:30 AM

Hi there,

I have a radMultiColumnComboBox1 which resizes the contents of its dropdown grid perfectly the first time its DataSource is set. It doesn’t resize itself, however, upon subsequent assignments to its DataSource.

This is illustrated by the two attachments. In “DataSourceSetForFirstTime.png,” everything looks great. In “DataSourceSetTheSecondTime.png,” however, the grid retains its original width even though the data no longer necessitates it.

The code I have is shown below. (As the commented out portions suggests, I’ve tried a number of things.) Can you please help me get the grid to resize itself whenever its DataSource changes?

                radMultiColumnComboBox1.AutoFilter = true;

                radMultiColumnComboBox1.EditorControl.MasterTemplate.ShowRowHeaderColumn = false;

                RadGridView gridViewControl = this.radMultiColumnComboBox1.EditorControl;

                gridViewControl.MasterTemplate.AutoGenerateColumns = false;

                gridViewControl.Columns.Clear();

                //Specify the columns which the dropdown should show

                for (int i = 0; i < lookupDescription.fields.Count(); i++)

                    gridViewControl.Columns.Add(new GridViewTextBoxColumn(lookupDescription.fields[i]));

                //Set the suggestions

                radMultiColumnComboBox1.DataSource = suggestions;

                //Tweak the width. http://www.telerik.com/help/winforms/gridview-columns-resizing-columns-programatically.html

                radMultiColumnComboBox1.AutoSizeDropDownToBestFit = true;

                radMultiColumnComboBox1.BestFitColumns(true, true);

                //gridViewControl.AutoSize = true; //This breaks things

                //gridViewControl.AllowAutoSizeColumns = true; //This has no visible affect

                radMultiColumnComboBox1.MultiColumnComboBoxElement.TextBoxElement.Text = comboText.curVal;

                radMultiColumnComboBox1.MultiColumnComboBoxElement.ShowPopup();

                radMultiColumnComboBox1.EditorControl.Update();

                radMultiColumnComboBox1.EditorControl.BestFitColumns(BestFitColumnMode.AllCells);

/*

                radMultiColumnComboBox1.DropDownSizingMode = SizingMode.UpDownAndRightBottom;

                radMultiColumnComboBox1.MultiColumnComboBoxElement.ResetLayout(true);

                radMultiColumnComboBox1.MultiColumnComboBoxElement.UpdateLayout(); */

                //radMultiColumnComboBox1.MultiColumnComboBoxElement.EditorControl.AutoSizeColumnsMode=GridViewAutoSizeColumnsMode.Fill;

 

Thank you,

Ben


1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 16 Apr 2013, 01:02 PM
Hi Ben,

Thank you for writing.

It seems that there is an issue with this case and the popup is not correctly sized. I have logged it in our 
Public Issue Tracking System and we will address it accordingly. To vote for it and subscribe for status updates, please follow this link: http://www.telerik.com/support/pits.aspx#/public/winforms/14783.

For the time being, to work around the issue, you can try calling the BestFitColumns method in the DropDownOpening event:
public partial class Form1 : Form
   {
       public Form1()
       {
           InitializeComponent();
 
           Random r = new Random();
           DataTable table = new DataTable();
           table.Columns.Add("ID", typeof(int));
           table.Columns.Add("Name", typeof(string));
 
           for (int i = 0; i < 10; i++)
           {
               table.Rows.Add(i, "Row with longer value " + i);
           }
 
           radMultiColumnComboBox1.DropDownOpening += radMultiColumnComboBox1_DropDownOpening;
           radMultiColumnComboBox1.AutoSizeDropDownToBestFit = true;
           radMultiColumnComboBox1.DataSource = table;
       }
 
       void radMultiColumnComboBox1_DropDownOpening(object sender, CancelEventArgs args)
       {
         //  radMultiColumnComboBox1.BestFitColumns();
       }
 
       private void button1_Click(object sender, EventArgs e)
       {
           Random r = new Random();
           DataTable table = new DataTable();
           table.Columns.Add("ID", typeof(int));
           table.Columns.Add("Name", typeof(string));
 
           for (int i = 0; i < 10; i++)
           {
               table.Rows.Add(i, "Row " + i);
           }
 
           radMultiColumnComboBox1.DataSource = table;
 
       }
   }

I hope this helps. Your 
Telerik Points have been updated for this report.
 

Regards,
Stefan
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
Tags
MultiColumn ComboBox
Asked by
Ben
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or