combobox databinding on char type column

A

Aamir Ghanchi

The selected index in a ComboBox does not change when
moving through the rows of the master table. The ComboBox
is filled with a char type column from a lookup table and
bind to a corresponding char type column in a master
table .

Details:
I have a combobox that has been filled with a char type
column of a lookup table by setting its DataSource to a
DataTable of a DataSet object and setting its
DisplayMember and ValueMember to the same char(4) column
of this lookup table. Then I bind the SelectedValue and
SelectedItem properties of this ComboBox to a
corresponding char column of the main DataTable of which I
am browsing the rows. all the other ComboBoxes and
TextBoxes get updated accordingly except for this one.
Other ComboBoxes are bond through int column.
Actually the this char bound ComboBox does update, but it
is not consistent. The lenght of char column in the lookup
table and the main table is 4. The DataSet schema shows
the types of the corresponding columns as string type.

What am I doing wrong?

thanks for any help.

Aamir
 
A

Aamir Ghanchi

Problem solved:
Besides other things that fixed it, I noticed that when you change the
datatype of a MS SQL table column from char to vchar it leaves
trailing spaces after the values (specially when the actual length of
the contents in the column is less than the length of the column
defined). If this happens then the Databinding will not work. To
prevent this from happening Trim the values in the Lookup table and
the Data table in MS-SQL database. or Trim them when reading them
into the program in the SelectCommand.
 

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

Top