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