Solved

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

Posted on 2004-09-02
13
542 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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 …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

679 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