471,310 Members | 1,390 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,310 software developers and data experts.

Why does a binding a combobox to datatable not work the same as da

If a bind a data table to a comboxbox as appose to merging the table into a
dataset the selectedvalue property does not work consistently

On loading of a form:
A datatable is created from a database with ID 1 - 10 and values associated
e.g. Red, green, blue.

An additional item is added to the datatable to reflect a non selected item
with an ID of 0 for no colour selected.

on reading of data, when a value of 0 is set to the selected value the
following error occurs:

Parameter name: '-2147483613' is not a valid value for 'index'

But if the datatable is first merged with a data set and the dataset's table
is reference to the combobox, there's no problem.
Sample code Try commented, then uncommented:

Sub Load
dtDataTable = ColoursRead()


With cboColours
.DataSource = dtDataTable
'.DataSource = _referenceData.Tables("Banks")
.DisplayMember = "Name"
.ValueMember = "pkiColourID"
End With
End Sub

Sub SelectValue()
cboColours.SelectedValue = 0
End Sub

pkiColourID Name
0 No Colour
1 Red
2 Green
3 Blue
Jul 21 '05 #1
0 928

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Michael C# | last post: by
4 posts views Thread by Jim Shaffer | last post: by
3 posts views Thread by amber | last post: by
3 posts views Thread by Simon Tamman | last post: by
3 posts views Thread by Max | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.