PC Review


Reply
Thread Tools Rate Thread

Combox SelectedValue databinding

 
 
Gary Shell
Guest
Posts: n/a
 
      13th Jul 2004
I have a pair of combo boxes on a form. Both have their SelectedValue
property bound to a column on a table called "Input_Output". One column is
called "Class" and the second is called "SubClass". Each combobox has its
datasource, displaymember and SelectedValue member bound to separate tables
thru individual datatsets thru individual data adapters. The two tables are
"Class" and "SubClass".

I use parameterized query to populate the list portion of the SubClass Combo
box based on the selection displayed in the Class combobox. When editing
existing records everything works just fine. I can select a new Class and
the SubClass combobox list content changes as expected. The text displayed
in the SubClass combo changes to the first item in the list, EVEN IF NO
SELECTION IS MADE IN THE SUBCLASS COMBO. Updates to the data adapter
successfully update the database. So far so good.

If I attempt to ADD a new record, I have trouble. Initially the Class combo
and SubClass comboboxes are blank. Selecting an item in the Class combo
cause the SubClass combobox to be repopulated, with the first entry
displayed. When I execute the following code the SubClass combobox
immediately goes blank:

Me.BindingContext(Me.DsInput_Output, "Input_Output").EndCurrentEdit()
If DsInput_Output.HasChanges(DataRowState.Added) Then
'only if there really are adds to be processed
sqldaInput_Output.Update(Me.DsInput_Output)
strTheItem = Me.cmbIO_Name.Text
End If

The SubClass combo actually goes blank on the EndCurrentEdit method. So, of
course, the database gets a null for that column when the Update method is
executed. If I set a breakpoint on the EndCurrentEdit I can see that the
SubClass combo box TEXT, and SELECTEDVALUE properties both have the expected
string value. After the EndCurrentEdit they are NOTHING.

Now the strange part. If I actually select an item in the SubCLass combo the
EndCurrentEdit and subsequent code work just fine. Why is this explicit
selection necessary? Why is the EndCurrentEdit setting the SelectedValue
property to nothing? I'm confused and frustrated.

Google searches have turned up little, except to note that apparently the
combobox is a bit buggy. Specifically when placed on a tab page. (And you
guessed it, I am using these on a tab page. Sigh.)

Anyone else fought this battle? Anyone win? Should I just use a third
party combobox and cut my losses?

Thanks,
Gary


 
Reply With Quote
 
 
 
 
Gary Shell
Guest
Posts: n/a
 
      13th Jul 2004
I found the root cause and a solution. There appears to be a difference in
the way the databinding works on an edit versus an add new. The dataset's
item collection is updated when I repopulate the SubClass combobox during an
Edit, but it is NOT updated when I repopulate the SubClass combobox during
an Add new. (It is updated just fine if I actually select something from the
SubClass combo in either case.)

Just before the EndCurrentEdit is executed, I can look at the SubClass
combobox SelectedValue property and the dataset item collection and see that
when editing an existing record, the two items have the same value. When
adding a new record, the SelectedValue property is correct and the dataset
item is NULL. It appears that the EndCurrentEdit, repopulates the bound
SubClass combobox, during an edit with the correct data, and during an add
new with a null. The update method that follows takes whatever is in the
dataset's item collection and sends it to the database.

My workaround was actually quite simple. Prior to executing the
EndCurrentEdit I set the dataset item collection entry to the value
contained in the SubClass combobox's SelectedValue property. Now the
EndCurrentEdit no longer sets the SelectedValue property to nothing AND the
update method sends the correct data to the database.

Whew!!!!! Two 14 hour days latter and I'm on to the next bug. <grin>

Gary

"Gary Shell" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> I have a pair of combo boxes on a form. Both have their SelectedValue
> property bound to a column on a table called "Input_Output". One column is
> called "Class" and the second is called "SubClass". Each combobox has its
> datasource, displaymember and SelectedValue member bound to separate

tables
> thru individual datatsets thru individual data adapters. The two tables

are
> "Class" and "SubClass".
>
> I use parameterized query to populate the list portion of the SubClass

Combo
> box based on the selection displayed in the Class combobox. When editing
> existing records everything works just fine. I can select a new Class and
> the SubClass combobox list content changes as expected. The text

displayed
> in the SubClass combo changes to the first item in the list, EVEN IF NO
> SELECTION IS MADE IN THE SUBCLASS COMBO. Updates to the data adapter
> successfully update the database. So far so good.
>
> If I attempt to ADD a new record, I have trouble. Initially the Class

combo
> and SubClass comboboxes are blank. Selecting an item in the Class combo
> cause the SubClass combobox to be repopulated, with the first entry
> displayed. When I execute the following code the SubClass combobox
> immediately goes blank:
>
> Me.BindingContext(Me.DsInput_Output, "Input_Output").EndCurrentEdit()
> If DsInput_Output.HasChanges(DataRowState.Added) Then
> 'only if there really are adds to be processed
> sqldaInput_Output.Update(Me.DsInput_Output)
> strTheItem = Me.cmbIO_Name.Text
> End If
>
> The SubClass combo actually goes blank on the EndCurrentEdit method. So,

of
> course, the database gets a null for that column when the Update method is
> executed. If I set a breakpoint on the EndCurrentEdit I can see that the
> SubClass combo box TEXT, and SELECTEDVALUE properties both have the

expected
> string value. After the EndCurrentEdit they are NOTHING.
>
> Now the strange part. If I actually select an item in the SubCLass combo

the
> EndCurrentEdit and subsequent code work just fine. Why is this explicit
> selection necessary? Why is the EndCurrentEdit setting the SelectedValue
> property to nothing? I'm confused and frustrated.
>
> Google searches have turned up little, except to note that apparently the
> combobox is a bit buggy. Specifically when placed on a tab page. (And

you
> guessed it, I am using these on a tab page. Sigh.)
>
> Anyone else fought this battle? Anyone win? Should I just use a third
> party combobox and cut my losses?
>
> Thanks,
> Gary
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Filter a combox based on selection from another combox David Microsoft Access Form Coding 2 22nd Jan 2010 12:05 AM
Databinding expressions are only supported on objects that have a DataBinding event jobs Microsoft ASP .NET 0 26th Sep 2007 12:54 AM
DataBinding a ListBox's SelectedValue to integer field from DataSet gives error dtblankenship@gmail.com Microsoft ASP .NET 4 13th Jan 2005 07:13 PM
Databinding Bible (REPOST FROM m.p.d.f.WindowsForms.Databinding) a Microsoft ADO .NET 1 16th Jul 2004 03:26 AM
combox and databinding Eva Microsoft VB .NET 10 28th Oct 2003 06:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:33 PM.