How to automatically set MultiColumnComboBox DropDown Width to display column width in full
Hello everybody,
I am using MultiColumnComboBox in my WinForm project. I want to be able to achieve same result as in Pic1 in the attached file. Pic2 in the attached file is my result and pic3 is my design time settings of MultiColumnComboBox
Thanks in advance for the assistance
Attachment: file_d106bb84.rar
SIGN IN To post a reply.
9 Replies
1 reply marked as answer
VR
Vijayalakshmi Roopkumar
Syncfusion Team
April 19, 2021 12:34 PM UTC
Hi Paul,
Thank you for contacting Syncfusion Support.
We have observed that your requirement to set the width for the DropDown list to full column width, for this the DropDownWidth property of MultiColumnComboBox is used. This property allows to autosize the text of the items of MulticolumnComboBox. However on observing your screenshot, your sample contains a MaxDropDownItems as 8, and DropDownWidth as 208, so only it shrinks. However, please set the DropDownWidth to higher value. Please find the screenshot for the same:
Screenshot:
The same has been explained in the following sample.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/MultiColumnComboBox_droddownwidth184812705766101659
Please try with the above solution and let us know if it is helpful
Regards.
Vijayalakshmi VR
PA
Paul
April 21, 2021 08:45 AM UTC
Hello Vijayalakshmi,
Attachment: CS_1262f707.rar
Thanks for prompt response.
The requirement I am looking for is I want the DropDownWidth to be determined at runtime based on the cumulative columnwidth fo the DropDown columns.
I have seen a similar requirement in one of your demos I have been studying and I have attached it.
Attachment: CS_1262f707.rar
VR
Vijayalakshmi Roopkumar
Syncfusion Team
April 22, 2021 07:42 AM UTC
Hi Paul
Thank you for your update.
To autosize the column of MultiColumnComboBox, you can use the following code:
Code:[C#]
|
//To auto size the columns width based on cell values
grid.Grid.Model.ColStyles[1].AutoSize = true;
grid.Grid.Model.ColStyles[1].WrapText = false;
//To update the dropdown width based on column width
this.multiColumnComboBox1.DropDown += MultiColumnComboBox1_DropDown;
private void MultiColumnComboBox1_DropDown(object sender, EventArgs e)
{
this.multiColumnComboBox1.DropDownWidth = grid.Grid.Model.ColWidths[1];
} |
The same has been demonstrated in the following sample:
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/MultiColumnComboBox-1140309067
ScreenShot:
Regards
Vijayalakshmi V.R.
PA
Paul
April 22, 2021 11:19 AM UTC
Hello Vijayalakshmi,
Attachment: file_ea88ff70.rar
Thanks for the assistance and prompt response.
I have implemented your suggestions but does not seem to get satisfactory result, The content of the second column is wider than the first. Maybe I am doing something wrong so I have my code snippet below and I also have my result in the attachment.
public partial class frmSupplierFormNew : Form
{
public frmSupplierFormNew()
{
grid = this.cboAccount.ListBox as GridListControl;
//To auto size the columns width based on cell values
grid.Grid.Model.ColStyles[1].AutoSize = true;
grid.Grid.Model.ColStyles[1].WrapText = false;
grid.Grid.Model.ColStyles[2].AutoSize = true; //because I two columns.
grid.Grid.Model.ColStyles[2].WrapText = false;
private void Form4_Load(object sender, EventArgs e)
{
try
{
cboAccount.DataSource = GetSupplierLookups;
cboAccount.ValueMember = "SupplierCode";
cboAccount.DisplayMember = "SupplierCode";
cboAccount.DropDown += MultiColumnComboBox1_DropDown;
private void MultiColumnComboBox1_DropDown(object sender, EventArgs e)
{
this.cboAccount.DropDownWidth = grid.Grid.Model.ColWidths[1] + grid.Grid.Model.ColWidths[2];
}
Attachment: file_ea88ff70.rar
VR
Vijayalakshmi Roopkumar
Syncfusion Team
April 25, 2021 02:04 PM UTC
Hi Paul
Thank you for your update.
We have suspect whether column width may be not set correctly. So we request you to invoke the ResizeToFit method for grid column width before setting the dropdown width for MultiColumnComboBox.
Please refer the below document for more information:
If you still faces any problem with it, we would like to schedule a web session with you to look the actual problem at your environment. So please let us know your availability , so that we can check and arrange the meeting accordingly.
Regards,
Vijayalakshmi VR
PA
Paul
April 26, 2021 08:59 AM UTC
Hello Vijayalakshmi ,
I am having this error: gridlistcontrol' does not contain a definition for 'colwidths' and no accessible extension method 'colwidths'
Thanks
VR
Vijayalakshmi Roopkumar
Syncfusion Team
April 27, 2021 10:02 AM UTC
Hi Paul
Thank you for your update.
You need to access the colwidths and ResizeToFit method as shown in below code.
Code:[C#]
We can pass the whole table as range or particular column width as GridRangeInformation in ResizetoFit Method.
|
this.multiColumnComboBox1.DropDownWidth = control.Grid.Model.ColWidths.ResizeToFit(GridRangeInfo.Col(2), GridResizeToFitOptions.NoShrinkSize); |
If you still faces any problem with it, please provide issue reproducible sample. Also let us know your availability to schedule a meeting with you in order to avoid further delays. It would be very helpful for us to check and proceed on it further.
Regards,
Vijayalakshmi VR
PA
Paul
May 6, 2021 04:31 PM UTC
Hello Vijayalakshmi,
I finally got the requirement I wanted so I decided to share it.
I removed all the MultiColumnComboBox controls I already had on the forms and added them again.
I did not even have to use the code below. I did not set DropDownWidth property.
//To update the dropdown width based on column width
this.multiColumnComboBox1.DropDown += MultiColumnComboBox1_DropDown;
Thanks for your patience and assistance
Marked as answer
EM
Elakkiya Muthukumarasamy
Syncfusion Team
May 7, 2021 11:20 AM UTC
Hi Paul ,
Most welcome. We are glad to know that the reported issue is resolved at your end. Please get back to us if you need any other assistance. We are happy to assist you.
Regards,
Elakkiya
SIGN IN To post a reply.