473,416 Members | 1,546 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Change to combobox lost when trying to update datatable

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()
BindingContext(dtItems).EndCurrentEdit()
Dim row As DataRow
row = dtItems.NewRow()
dtItems.Rows.Add(row)
dtItems.Rows.Remove(row)

Dim intRowIndex As Integer
intRowIndex = dgItems.CurrentRowIndex
dgItems.CurrentRowIndex = 0
dgItems.CurrentRowIndex = intRowIndex
If Not dtItems.GetChanges Is Nothing Then
MessageBox.Show("Changed")
daMain = New OleDbDataAdapter(strItemSelectSQL,
dbConn)
Dim command_builder As OleDb.OleDbCommandBuilder
command_builder = New
OleDb.OleDbCommandBuilder(daMain)
daMain.Update(dtItems)
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
4 3323
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.

Cor
Nov 20 '05 #2
Cor,

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.

Rob
Nov 20 '05 #3
Rob,

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.

Cor
Nov 20 '05 #4
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: thomaz | last post by:
I use the DataSource like below to fill a Combobox: comboBox1.DataSource = dataSet1.Tables; comboBox1.DisplayMember = "ProductName"; When the user types any keyboard key i use the DROPDOWN...
20
by: MadCrazyNewbie | last post by:
Hey group, I keep getting the following error: "An unhandled exception of type 'System.IndexOutOfRangeException' occurred in system.data.dll Additional information: There is no row at...
30
by: dbuchanan | last post by:
ComboBox databindng Problem == How the ComboBox is setup and used: My comboBox is populated by a lookup table. The ValueMember is the lookup table's Id and the DisplayMember is the text from a...
7
by: Simon Verona | last post by:
I posted this in dotnet.languages.vb.controls but thought I'd post here as well.. I have a combobox that is bound to a dataview generated from a dataset. The dataset has a single table...
5
by: Peter M. | last post by:
I'm struggling with combobox databinding with something I consider a bug... I'm binding my combobox to an array of structs. The struct exposes two public properties, ID and Name, to be used as...
10
by: Marc R. | last post by:
Hi all, I edit records using a form that have multiple control bind on Dataview, But I don't want to update right always to database, I would like to delay until all Changes (add all new...
2
by: osmarjunior | last post by:
Is there a way to change manually the RowState property of a DataRow, in a DataTable?? I wanna create a DataTable in memory, so I do the following: DataRow row = tbl.DataTable.NewRow(); row =...
12
by: Gerhard | last post by:
This is bizarre... Im having problems with the combobox AfterUpdate event: Im running Access 2003. I created an unbound combobox with 3 columns on a form. The Row Source is from a table....
2
by: kurtzky | last post by:
i created a form that should function as follows: i will enter a number in a textbox..then it should query from the database all the records which has that number..these records will have a...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.