Lookup drowdown not changed to default after BO.Clear()


http://forum.strataframe.net/Topic32092.aspx
Print Topic | Close Window

By Govinda Berrio - 6/6/2013 9:02:24 AM
Hello all, 

Maybe someone can suggest a workaround for this problem: I have a maintenance screen where one of the fields is edited using a SF lookup dropdown list. Editing works fine in everyway, but when I do a BO.Clear() the selected Text is still visible in the dropdown. The control is disabled as it should be when the BO is Idle but, the Text of the previously selected value is still visible. I would like it show the Top Most Item or at least display no selection (blank). 

I have attached a sample project that demonstrates the problem. 

Thank You, 
Govinda
By Govinda Berrio - 6/6/2013 9:05:33 AM
Oops
By Ben Chase - 6/6/2013 9:35:15 AM
Is that posted project a solution to your problem? 
By Govinda Berrio - 6/6/2013 9:39:45 AM
No. I neglected to attach the project on the initial post, so I replied and attached it.
By Ben Chase - 6/7/2013 4:31:49 AM
OK, the problem is that the RemoveBinding() method in the BusinessLayer class cannot force the text back to String.Empty because none of the items in the data source matches that string.  

So, I've modified the RemoveBinding() method to handle the situation better.  Your options are:

1) Manually call this.comboBox1.SelectedIndex = 0; when you call bo.Clear();
2) Change the BusinessLayer.vb source code and recompile it:
Private Sub RemoveBinding(ByVal ControlToRefresh As Control, ByVal PropertyName As String)            '-- Establish locals            Dim loPropInfo As PropertyInfo             '-- Check to see if the bindings have already been removed            If ControlToRefresh.DataBindings.Count > 0 Then                '-- If there are data bindings, but no data, then clear the data bindings to prevent errors                ControlToRefresh.DataBindings.Clear()                 '-- Set the property value                Dim combo As System.Windows.Forms.ComboBox = TryCast(ControlToRefresh, System.Windows.Forms.ComboBox)                If combo IsNot Nothing Then                    '-- We need to clear the combo box                    '-- First try to set the text on the combo box                    combo.Text = String.Empty                     '-- If the text could not be set, then either clear the selected value or set to the top index if it has a data source                    If Not String.IsNullOrEmpty(combo.Text) Then                        If combo.DataSource Is Nothing Then                            '-- Clear the selected value                            combo.SelectedValue = Nothing                        ElseIf combo.Items.Count > 0 Then                            '-- Set to the top index                            combo.SelectedIndex = 0                        End If                    End If                Else                    '-- Get the property info                    loPropInfo = TypePropertyCache.GetPropertyInfo(ControlToRefresh.GetType(), PropertyName)                     '-- Clear out the value                    loPropInfo.SetValue(ControlToRefresh, GetSystemTypeDefaultValue(loPropInfo.PropertyType), Nothing)                End If            End If        End Sub
You can replace the whole RemoveBinding() method with that.  The BusinessLayer.vb file is in the MicroFour StrataFrame Business project.  The code starts on line 3535.
By Govinda Berrio - 6/7/2013 4:49:39 AM
Thank You, Ben!

I will use your code. 

Govinda

Site Map - Home - My Account - Forum - About Us - Contact Us - Try It - Buy It

Microsoft, Visual Studio, and the Visual Studio logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.