Refreshing databound ComboBox error

Hello,
I am very new to vb.net and I would appreciate any help offered!

I have a simple form with the following items placed on it:
   Two ComboBoxes: cmbLanguage and cmbLanguageVars.
   Two DataAdapters: daLanguage and daLanguageVars
   Two DataSets: dsLanguage and dsLanguageVars

Both comboBoxes are databound (Microsoft Access).

As the form loads, cmbLanguage is populated with the names of different languages, cmbLanguageVars is simply left blank.
The aim is that when a language is selected from cmbLanguage, then cmbLanguageVars is populated.

The SQL query for daLanguage:
   SELECT LANG_NAME, LANG_ID FROM tblLanguage

The SQL query for daLanguageVars:
   SELECT LANG_NAME, VAR_NAME FROM tblLanguageVars WHERE (LANG_ID =  )

It should be noted that "LANG_ID" from daLanguage is used in the second SQL query.

I can offer this information about the databinding:

cmbLanguage
DataSource:dsLanguage.tblLanguage
DisplayMember:LANG_NAME
ValueMember:LANG_ID

cmbLanguageVars
DataSource:dsLanguageVars.tblLanguageVars
DisplayMember:VAR_NAME

As the form loads, cmbLanguage gets populated:
   daLanguage.Fill(dsLanguage)
As the SelectedIndex from cmbLanguage changes, I populate cmbLanguageVars:
   daLanguageVars.SelectCommand.Parameters("LANG_ID").Value = cmbLanguage.SelectedValue
   daLanguageVars.Fill(DsLanguageVars)

This all works fine.
The second ComboBox cmbLanguageVars gets populated with the language variables in the selected language.

The problem is that if the user changes his mind and selects another language, then the variables are added to the existing items in the cmbLanguageVars!

I thought that if I cleared the ComboBox beforehand:
   cmbTest.Items.Clear()
then the problem would be solved.

Unfortunately, I receive the following error:
   Can't modify the Items collection when the DataSource property is set.
As I need to have the controls databound, this is a problem.

Thank you for your time taken in reading this,

Andreas.


Answer this question

Refreshing databound ComboBox error

  • dlawler

    you must clear the underlinig datasource, you see the items collection is only if you don't have it bound to a datasource, hence the error.

    You dould go DSlanguagevars.tables("mytable").rows.clear

    Hope this helps, you can find other useful datagrid information here

    http://www.syncfusion.com/FAQ/WinForms/default.asp#44

  • Tadek

    Joe,

    thank you ever so much for your help.

    I'll check it out tomorrow (it's 01:40 here now!) and let you know how I got on.

    Thanks once again!

  • Refreshing databound ComboBox error