Combobox issue

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
 
G

Guest

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();
 
A

Antonio Paglia

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
 
C

Cor Ligthert [MVP]

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
 
A

Antonio Paglia

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Datacombo issue 1
ComboBox Code 4
Combobox with a dynamic list 12
listView - filling it with datareader 3
Combobox Datasource & Binding Custom Objects 5
ListView Control 7
ListView Help 1
Multiple listings 1

Top