I'm creating a combobox in runtime and trying to manually set a% of 'default'%, but I realized that even setting a value inside the combo manually is not selected. p>
I already checked if the data type beats (both are SelectedValue
).
Below the code where I create the combo:
ComboBox cmb = new ComboBox()
{
DropDownStyle = ComboBoxStyle.DropDown,
BackColor = Color.FromArgb(210, 211, 213),
ForeColor = Color.Black,
Location = new Point(5, y),
Size = new Size(265, 10),
Font = new Font("Verdana", 11f, FontStyle.Regular),
FlatStyle = FlatStyle.Popup,
AutoCompleteMode = AutoCompleteMode.SuggestAppend,
AutoCompleteSource = AutoCompleteSource.ListItems,
Tag = null
};
cmb.DataSource = null;
cmb.ValueMember = "Id";
cmb.DisplayMember = "Login";
cmb.DataSource = UsuarioDB.FindAll().Where(x => x.Id > 0).OrderBy(x => x.Login).ToList();
cmb.SelectedValue = (long)1; //Aqui estou setando manualmente o valor para testar
There are three things to punctuate:
long
property is correct with all the records, but the DataSource
property is empty; Items
empty, the combo shows the values exactly as I need (ie, running) and when changing the selected value and trying to capture by Items
the value comes right. SelectedValue
manually, however this works fine. Any idea what it might be?