Solved

ComboBox resetting to original value when datarow.endedit() is called

Posted on 2004-09-02
13
504 Views
Last Modified: 2012-06-27
I have a combobox on a form that has it's text property bound to a dataset and it's itemcollection is entered through the form designer.   When I change the value in the combo box the dataset is not getting updated with the new value.   Therefore when I call the dataadapter update function the changes aren't updated in the database.

I've tried using the beginEdit() and endEdit() functions on the datarow and that doesn't work.   As soon as the endEdit() is called the combobox reverts back to it's original value.

Any help is appreciated.    Thanks.
0
Comment
Question by:jeff411
  • 7
  • 4
13 Comments
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11965189
Shouldn't  the selectedItem be bound instead of the text ?
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11965210
Also what type is the bound column, the text returns a string, if the underlaying field is numeric it will fail aswell
0
 
LVL 1

Author Comment

by:jeff411
ID: 11966636
The field it is bound to is a string and I've tried selectedItem, selectedValue, Text and every combination of the three.   The dataset never gets updated because it doesn't think there are changes in that field.
0
 
LVL 1

Author Comment

by:jeff411
ID: 11966945
I have added CType(dsCurrentRMA.RMA.Rows(0), dsRMA.RMARow).Status = cbRMAStatus.Text to write the value directly to the dataset before calling the endEdit function.   This seems to update the database fine now, but that's more like a work around and I'm still interested in a solution to this problem.
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11970664
Hi jeff411,

Could you post some code. Because I've tried to recreate your problem and the only way I can recreate it is if I try to update right after changing the combobox. If I change record or field than it should work.

RB
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:jeff411
ID: 11972325
RonaldBiemans,

I have been updating the combobox and then calling update.    So what you are saying is that if I change the combobox and then change a field the combobox will update, but if I just change the combobox it won't?
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11972350
Yes, because if you haven't moved from the combobox it doesn't know that it has changed. But if you give me a minute maybe I have a solution for that.
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11972422
Hi Jeff411,

before you update do something like this

        Me.BindingContext(yourdatasource).EndCurrentEdit()

yourdatasource should be your dataset or datatable which you use to bind to the text of your combobox

so if you did something like this

        ComboBox1.DataBindings.Add("Text", dataset.tables(0), "test")

do

        Me.BindingContext(dataset.tables(0)).EndCurrentEdit()
0
 
LVL 1

Author Comment

by:jeff411
ID: 11976624
Here is my onload function.   What I'm doing is taking the RMA datarow from the dataset where they opened the RMA from and importing it into the RMA details form; saving me from having to wait to fill another dataset.

        dsCurrentRMA.Clear()
        dsCurrentRMA.RMA.ImportRow(frmForm.DsRMA1.RMA.Select("RMANumber = " + CStr(m_recordIndex))(0))
        Me.BindingContext(dsCurrentRMA.RMA).Position = 0
        dsCurrentRMA.RMA.Rows(0).BeginEdit()

Here is my Save function ( on button click )

            dsCurrentRMA.RMA.Rows(0).EndEdit()
            dbcomp.UpdateRMA(dsCurrentRMA)
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11988527
Hi Jeff411,

Then try this before the update and see if it works

Me.BindingContext(dscurrentrma).EndCurrentEdit()
 dbcomp.UpdateRMA(dsCurrentRMA)
0
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 500 total points
ID: 11988537
maybe this it better

Hi Jeff411,

Then try this before the update and see if it works

Me.BindingContext(dscurrentrma.rma).EndCurrentEdit()
 dbcomp.UpdateRMA(dsCurrentRMA)
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now