Hi,
I have recently started developing a system using CSLA and have come up with a problem with Combobox binding I cannot find a solution to.
I have a Business object with some foreign key fields which I am editing through a windows form. One of the fields is a currencyID field where I present a ComboBox which allows the usere to pick a currency using its description. The Combo box is populated using an NameValue List and displays perfectly. The selectedvalue property is set to the underlying binding source for the BusinessBase object and is being set correctly. However, if I tab from the field the text portion of the combo is cleared and I receive a null conversion error from the error provider. Even though the error is set the underlying property appears to still be set correctly.
The only way I can get around this at present is to include a readonly description field in the root object and reference this in the databindings 'text' field which from other forum discussions should be left blank. Has anyone any ideas where I am going wrong with this?
Thanks in advance for any assistance provided.
I have resolved this by switching from the MS Combobox to the Combobox supplied by Janus.
I added the Janus Combo box to a form manually. Then I dragged my NameValue List onto the Combo setting up the binding. I switched the DataSourceUpdate mode to OnPropertyChanged for the selected value which defaults to OnValidation. I then cleared the DisplayMember and Value member properties to prevent them being set in the InitializeComponent Sub. (When left the application compained they did not exist event though they were se to expected Key and Value respectively). In my load I then added following lines:
Me
.CurrencyNVListBindingSource.DataSource = CurrencyNVList.GetList() Me.CurrencyIDComboBox.DataSource = CurrencyNVListBindingSourceCurrencyIDComboBox.DisplayMember =
"Value"CurrencyIDComboBox.ValueMember =
"Key"Everything as a result worked fine. Now who was that who told me there was no need for third party tools with Visual Studio 2005?
Regards,
David,
I would expect that this is a regular requirement and expect I am doing something stupid. However, I am getting nowhere on support sites. Using the MS Dropdown I get the following properties in designer.
'MSCurrencyIDComboBox1
'Me
.ReadWriteAuthorization1.SetApplyAuthorization(Me.MSCurrencyIDComboBox1, False) Me.MSCurrencyIDComboBox1.DataBindings.Add(New System.Windows.Forms.Binding("SelectedValue", Me.ControlCompanyBindingSource, "CurrencyID", True, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)) Me.MSCurrencyIDComboBox1.DataSource = Me.CurrencyNVListBindingSource Me.MSCurrencyIDComboBox1.DisplayMember = "Value" Me.MSCurrencyIDComboBox1.FormattingEnabled = True Me.MSCurrencyIDComboBox1.Name = "MSCurrencyIDComboBox1" Me.MSCurrencyIDComboBox1.ValueMember = "Key"On my own Initialization of the component I have:
Me.CurrencyNVListBindingSource.SuspendBinding() Me.CurrencyNVListBindingSource.DataSource = CurrencyNVList.GetList()MSCurrencyIDComboBox1.DataSource = CurrencyNVListBindingSource
MSCurrencyIDComboBox1.DisplayMember =
"Value"MSCurrencyIDComboBox1.ValueMember =
"Key" Me.ControlCompanyBindingSource.ResumeBinding()What I am trying to find out is what I am missing. Selected value is being set fine and forwarded to B.O. but display is blank on attempting to leave the combo control.
Janus control got following from designer and my initialization similar to MS control above.
Me.CurrencyIDComboBox.ComboStyle = Janus.Windows.EditControls.ComboStyle.DropDownList Me.CurrencyIDComboBox.DataBindings.Add(New System.Windows.Forms.Binding("SelectedValue", Me.ControlCompanyBindingSource, "CurrencyID", True, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)) Me.CurrencyIDComboBox.Name = "CurrencyIDComboBox" Again any help in identifying what the problem is would be appreciated. I would prefer not to use the Janus COntrol if unnecessary as I prefer additional properties available in MS control.
Regards
Me.CurrencyNVListBindingSource.DataSource = CurrencyNVList.GetList()
That's how it works for me at least.I solved my problem. I previously wrote a code generator for building my classes from an Informix database. The primary keys in the database are mostly system allocated similar to an identity key in SQL Server. I translated this to a Long type in my classes which would be also be the type on all foreign keys referencing these tables. The NameValueList is defined as having a key of integer which while the system had no problem populating the class the selectedItem on the BoundCombo failed to display correctly. By changing my Foreign keys in my underlying datasource to Integer, Int32 or int16 all my binding issues were resolved.
Thanks to all those who tried to assist me.
Regards,
GinoK
Copyright (c) Marimer LLC