We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Autocomplete Combo box questions.

I am creating an autocomplete combo box dynamically and adding it to a group control.
I am resizing the combo box based on the width of the selected text.  I want the dropdown width
the be the size of the largest string in the list.  The Dropdown width does not change when I set it
also I want to be able to restrict input to whats in the list when I set the allownew text to false it seems to disable my
autocompled functionality.



        private void btnAdd_Click(object sender, EventArgs e)
        {
            //TextBox txtSeg = new TextBox();
            //txtSeg.Text = cboSegment.Text;
            //AutoSizeTextBox(txtSeg);

//            txtSeg.Location = new Point(mYlocation, 30);
  //          mYlocation += txtSeg.Width + 10;

    //        this.Controls.Add(txtSeg);

            ComboBoxAutoComplete mCboSegment = new ComboBoxAutoComplete();
            List<String> mNewList = mSegmentList.ToList<String>();
            mCboSegment.DataSource = mNewList;

            mCboSegment.AutoCompleteCustomSource.AddRange(mSegmentList.ToArray<String>());
            //mCboSegment.AutoCompleteCustomSource.AddRange({ "One","two","three"});
            mCboSegment.AutoCompleteSource = AutoCompleteSource.CustomSource;
            mCboSegment.Location = new Point(mYlocation, 20);
            mCboSegment.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            mCboSegment.SelectedItem = 1;
            mCboSegment.SelectedValueChanged += new EventHandler(MCboSegment_SelectedValueChanged);
            mCboSegment.Tag = cboNum;
            mCboSegment.DropDownWidth = 600;
            mCboSegment.AllowNewText = false;
            cboNum++;
            mYlocation += mCboSegment.Width + 10;
            //this.Controls.Add(mCboSegment);
           
            grpCombo.Controls.Add(mCboSegment);
        }

Attachment: WindowsFormsApplication4_d919371f.zip

5 Replies

SK Senthil Kumaran Rajan Syncfusion Team February 18, 2016 10:17 PM UTC

Hi Michael,

Thank you for contacting Syncfusion support.

The Width of the dropdown can be customized by the property named Preferred Width of the AutoCompleteControl in ComboBoxAutoComplete. Please make use of the below code example.

Code Example[C#]:

//To customize width of the AutoCompleteControl
mCboSegment.AutoCompleteControl.PreferredWidth = 250;


We have modified the sample based on the reported requirement and it can be downloaded from the below location.

Sample : https://www.syncfusion.com/downloads/support/forum/122108/ze/ComboBoxAutoComplete1303024503

Could you check with the above solution and let us know whether the provided solution is helpful? If not please provide some additional details about the reported requirement, it will be helpful for us to analyze and provide you a prompt solution as early as possible.

Regards,
Senthil


RA Rasika November 8, 2016 07:02 AM UTC

this solution doesn't set the preferedwidth of combobx dropdown. can you give any other solution to set autocomplete dropdown width of combobox.
thanks.


VI Vinothini Syncfusion Team November 9, 2016 06:28 AM UTC

Hi Rasika,   
   
Thank you for your update.   
   
As mentioned earlier, the width of the dropdown can be customized using PreferredWidth property. Please refer the below image and in that the width of the dropdown is set to 600 using the PreferredWidth property.   
   
 
Could you please check whether the PreferedWidth is set properly in your application? Or could you please give more details regarding your requirement?   
   
Regards,   
Vinothini   



RA Rasika November 9, 2016 07:22 AM UTC

the version i worked on is 10.4.0.53.
can you provide the above solution in vs2010 version.
thanks.



VI Vinothini Syncfusion Team November 10, 2016 06:23 AM UTC

Hi Rasika, 
 
Thank for your update. 
 
We have provided the sample in VS2010 and PreferredWidth property works as expected in the version 10.4.0.53. Please download the sample from the following location. 
 
 
Regards, 
Vinothini 


Loader.
Live Chat Icon For mobile
Up arrow icon