By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,168 Members | 2,599 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,168 IT Pros & Developers. It's quick & easy.

Change to combobox lost when trying to update datatable

P: n/a
I've got a form with a datagrid that displays a list of items, along
with several textboxes, comboboxes, etc., that display the details for
the selected item. The columns in the datagrid and the "details"
controls are both bound to fields in a dataview called dvItems. The
dataview is a subset of a datatable called dtItems, which is simply a
copy of all the data in a table called Items. The idea is to allow
the user to edit an item in either the datagrid or in the 'details'
form below it.

My initial problem was getting GetChanges to actually reflect the
changes that the user made. I tried calling
BindingContext(dtItems).EndCurrentEdit(), but that didn't seem to do
anything (also tried it with dvItems). The only way I could get it to
work was to add a dummy row to the table, then remove it, and then
change the CurrentRowIndex to 0 and then back to the previous index,
like so:

Private Sub SaveItemGridChanges()
Dim row As DataRow
row = dtItems.NewRow()

Dim intRowIndex As Integer
intRowIndex = dgItems.CurrentRowIndex
dgItems.CurrentRowIndex = 0
dgItems.CurrentRowIndex = intRowIndex
If Not dtItems.GetChanges Is Nothing Then
daMain = New OleDbDataAdapter(strItemSelectSQL,
Dim command_builder As OleDb.OleDbCommandBuilder
command_builder = New
End If
End Sub

Seems stupid, but it works. When the user clicks the save button, the
data is correctly updated with changes to either the datagrid or the
controls on the item details form below it.

Now I've got another problem, though. I've got a "Deactivate Item"
button which is supposed to set the status column for the currently
selected to "Inactive" and then save the record. I've got a combobox
that allows the user to manually change the status of an item, but
this button is supposed to provide a shortcut. I can't figure out a
way to directly update the column in the "current record" of the
dataview, so I figured I'd take the easy way out: Simply
programmatically change the value of the status combobox to the
correct value and then call the SaveItemGridChanges Sub.

The problem is that although the value of the combobox changes to
Inactive (cboStatus.SelectedValue = 6), it just changes back when I
call the SaveItemGridChanges sub. I'm not sure if this has to do with
the contortions this Sub goes thru to get the changes to be recognized
or what. I've tried taking out some or all of the code that forces
the GetChanges function to work, but then it just doesn't save. When
I manually change the status and the click the save button (which just
calls SaveItemGridChanges), it works fine. So apparently some event
is firing when I manually make the change that doesn't fire when I
programmatically set the value.

I've been working on this same stupid problem for about 5 hours now,
so any help would be greatly appreciated.
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies

P: n/a
Hi Rob,

This should normally be
If Not dtItems.GetChanges Is Nothing Then

If dtItems.HasChanges then

Where you are forcing with your add and remove a setting of the changes it
seems. However that should be nothing because an add and a remove of the
same means no change. I hope there is no addchanges before that code?

Your other problem I do not see directly the solution, however there I have
to think about the fact that the update does always an acceptchanges.

Nov 20 '05 #2

P: n/a

Thanks for the response.

A datatable doesn't support HasChanges. Only a dataset does. I
believe I tried it with a dataset as well, and it made no difference.

Nov 20 '05 #3

P: n/a

Sorry I misunderstand your problem.

The combobox textbox part is in my opinion the most buggy part of dotNet.

Therefore when you have problems with that text part of the combobox, try to
take another approach.

Not that it helps much, however to help you giving you the idea that you are
not the only one.

Nov 20 '05 #4

P: n/a
Ok, well that gives me something else to look at. I'll let you know
if I find a solution.
Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.