Combobox issue

  • Thread starter Thread starter Antonio Paglia
  • Start date Start date
A

Antonio Paglia

Hi people,

Dim rows as string = "item1;item2;item3....."
Combo.DropDownStyle = ComboBoxStyle.DropDownList
Combo.DataSource = rows.Split(";"c)
Combo.SelectedIndex = -1

The combo is placed inside an MDI Child form. When the form is showed, the
combobox allways apears with the first item selected.
What is wrong ???

Please, help me !!

TIA
 
I guess u gotta have a blank item at the start and then bind the control

[C#]
string rows = ";item1;item2;item3";
Combo.DataSource = rows.Split(';');
Combo.SelectedIndex = 1;
Combo.DataBind();
 
Unfortunately no.

I have noticed that adding items with

combo.items.Add "item1"
combo.items.Add "item2"

works fine

But whem I use DataTable or an Array as datasource don't work

If use DataTable I allways set

Combo.DisplayMember = dt.Columns(1).ColumnName
Combo.ValueMember = dt.Columns(0).ColumnName
 
Antonio,

There is a combobox bug, that can be workaround with setting the
selectedindex two times to -1. Can you try if that solves your problem.

I hope this helps,

Cor
 
I have tried but nothing....

If you want to see this issue, try this:

- Add new form1 and form2
- In form1 place a button and copy

Me.IsMdiContainer = True

LoadData() -------> load data into a dataset ds ( or
DataTable)

Dim dtNewTable As DataTable = ds.Tables(0)
dtNewTable.TableName = "Menu"
ds.Tables.Add(dtNewTable)

Dim f As New Form1
f.anyMethod(dsProducts)

f.MdiParent = Me
f.Show()


- In form2

Public Sub anyMethod(ByVal ds As DataSet)

cboDemo.DropDownStyle = ComboBoxStyle.DropDownList
cboDemo.DataSource = ds.Tables("Menu")
cboDemo.DisplayMember = "ProductName"
cboDemo.ValueMember = "ProductID"
cboDemo.SelectedIndex = -1
cboDemo.SelectedIndex = -1

End Sub
 
Back
Top