Hi
I have a peculiar problem. I have several fields on a winform among which two are txtRateID which is an UltraComboEditor and a txtRate field which is a text editor. All the fields are bound by code as below;
Private WithEvents bmStaffDetails As System.Windows.Forms.CurrencyManagerDim db As System.Windows.Forms.Binding
db = New System.Windows.Forms.Binding("Text", ds, "Staff.Rate ID") txtRateID.DataBindings.Add(db)
db = New System.Windows.Forms.Binding("Text", ds, "Staff.Rate") txtRate.DataBindings.Add(db)
db = New System.Windows.Forms.Binding("Text", ds, "Staff.Min Rate") txtMin.DataBindings.Add(db)
'Assign a currency manager bmStaffDetails = CType(BindingContext(ds, "Staff"), CurrencyManager)
'Fill the underlying table ds.Staff.Clear() daStaff.Fill(ds.Staff)
This works ordinarily and I can see the information on bound controls just fine and can also browse through records by calling appropriate fill methods. See image1 (http://www.infovis.biz/image.jpg) for how it works normally.
The problem comes when I assign the following code to the form;
Private Sub txtRateID_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtRateID.SelectionChanged Me.txtRate.Value = CStr(DLookup("[Rate]", "[Rates]", "[Rate ID] = """ & txtRateID.Value.ToString & """"))End Sub
The purpose of this code is to allow a user to select a txtRateID from drop down of UltraComboEdiitor and then for system to automatically lookup the corresponding Rate amount from the underlying table and assign this value to the txtRate field.
The problem is that after assigning this code I can not see any data in the bound fields any more, see Image2 (http://www.infovis.biz/image.jpg). But as the child records (marked by pink) are displaying fine, it is obvious that underling code is working fine, only the field binding has stopped working for some reason.
The UltraComboEditor txtRateID's drop down is also bound to the same Rates table, in case this is the reason for the problem. The code used to bind the Rates table to txtRateID's drop down is;
Cmd = New OleDb.OleDbCommand("SELECT Rates.[Rate ID] FROM Rates ORDER BY [Rate ID]", LocalConn) Reader = Cmd.ExecuteReader()
Me.txtRateID.Items.Clear() While (Reader.Read()) Application.DoEvents() StrValue = CStr(IIf(Reader.GetString(Reader.GetOrdinal("Rate ID")) Is Nothing, "", Reader.GetString(Reader.GetOrdinal("Rate ID")))) Me.txtRateID.Items.Add(StrValue) End While
How can I achieve what I am trying to achieve without this binding issue?
Thanks
Regards
Yahya
Hi Yahya,
I don't see anything wrong with what you are doing here, although it's often hard to tell from code snippets.
My guess is that if the binding simply stops working, then an exception probably occurred somewhere and was caught and ignored so you don't see it. This has happened to me in the past when binding a CheckBox (an inbox checkbox control, not an Infragistics UltraCheckEditor) to a field that allowed nulls. The checkbox is unable to handle null, but it raises no error when this occurs, it just silently fails and stops binding.
Try setting the Visual Studio IDE to break on all run-time exceptions and see if one is occurring in this case and that might give you a hint as to what's going wrong.