Unusual databound behaviour with combo boxes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've got a databound combo (databound to a System.Data.DataTable), but some
rather unpredicatable behaviour -- even though I have 8 rows in the source
table, only the first 6 are showing up in the items collection.

I've been scratching my head over this for a while now, but can't fathom
what could be to blame for this oddity.

Has anyone seen this behaviour before, or can think of any possible causes?
 
Rowland,

Although probably everyone who has used a bounded combobox has had at least
for him unpredictable behaviour, is this one new for me.

Can you show some code or check first when you set the datasource the
datastable with

messagebox.show(datatable.rows.count.tostring)

Cor
 
The simplest of simple code:

ds = m_Department.LoadList()

'Populate the dropdown
Cmb_Department.DataSource = ds.Tables("Departments")
Cmb_Department.DisplayMember = "Department"
Cmb_Department.ValueMember = "DepartmentID"

Now, when stopped in the debugger immeadiatly after all this,
Cmb_Department.Items collection differs to the ds.Tables("Departments").Rows
collection.

You can probably understand why I've been scratching my head a lot now :)
 
Rowland

And what does this give?
'Populate the dropdown
Cmb_Department.DataSource = ds.Tables("Departments") messagebox.show(ds.tables("Departments").rows.count.tostring)
Cmb_Department.DisplayMember = "Department"

Cor
 
From the debugger:
cmb_department.items.count 6 Integer
ds.tables("Departments").rows.count 8 Integer
 
Rowland,

It looks weird, what does this one give?

Dim count As Integer = DirectCast(BindingContext(cmb_department.DataSource),
_
CurrencyManager).Count()

Cor
 
That also gives a count of 6, although I'm not entirely sure why the cast to
CurrencyManager is done?
 
Rowland,
That also gives a count of 6, although I'm not entirely sure why the cast
to
CurrencyManager is done?

The answer on the last question is, I am checking your problem first in a
sample, and just changed another row, that is the only reason.

:-)

Than the last one we have however that should be absolute weird when this is
8
Dim count As Integer = DirectCast(ComboBox1.DataSource,
DataTable).rows.count

Cor
 
Well, for completeness:
ds.tables("Departments").rows.count 8 Integer
cmb_department.items.count 6 Integer
DirectCast(cmb_department.DataSource, DataTable).Rows.Count() 8 Integer
DirectCast(BindingContext(Cmb_Department.DataSource),
System.Windows.Forms.CurrencyManager).Count() 6 Integer
(ds.tables("Departments") is cmb_department.datasource) True Boolean
 
Rowland,

I think I am now in the same situation as you.

You can ofcourse create two arrays from the information. And than check
those in your quick watch window

You have already allmost all the code
\\\
dim myarray(ds.tables("Departments").rows.count) as string
for i as integer = 0 to ds.tables("Departments").rows.count -1
myarray(i) = ds.tables("Departments").rows(i)(Department).tostring
next
Stop
///
You can do the same for the combo, however you have that already in the
combobox.

However I find it weird as well.

Cor

Cor
 
Well, it's comforting to see that it's reproducible, but I've no idea what
the cause is, or how to work around it :(
 
Rowland and Cor,

What do you see if you bind the Departments DataTable to a DataGrid?

Sometimes viewing the source data this way will help debug an issue like
this.

Mike
 
This just gets wierder, I still get six rows:

DepartmentId Department FieldA FieldB FieldC
1 I MS02 M False
2 E MS02 M False
3 H MS02 M False
4 L MS02 M False
5 C (null) C False
8 C T MS02 M False

(the same six that are in the combo)
 

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

Back
Top