Delete value in combobox


Author
Message
Thomas Holste
Thomas Holste
StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)
Group: StrataFrame Users
Posts: 144, Visits: 618
Hi there,

I am using the combobox bound to a BO and also populated by a BO. Its bindingproperty is set to "selectedvalue" and its dropdownstyle to "dropdownlist". When the form starts, the combobox entry-field is empty. I then select one of the values from the listitems and enter the next field.

But what I can not do is deleting the choosen value and setting the combobox to its initial empty state.

I put some code in the keydown-evnmt to ckear it by setting the selectedvalue back to nothing (where it starts with) but this caused an error. The same with setting the selectedvalue to "".

I also tried setting the bindingproperty to text and then set its text-property to "", but this did not work too.

Can someone tell me what to do?

Best regards

Thomas
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Thomas,

You need to setup the TopMost properties of the combobox to get the desire functionality.  Look at the help file for more details, also in the forum there are plenty of post about it, here is one http://forum.strataframe.net/FindPost20564.aspx

Edhy Rijo

Thomas Holste
Thomas Holste
StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)
Group: StrataFrame Users
Posts: 144, Visits: 618
Hi Edhy,

thank you for your help. I thought of this possibility, but two things have kept me from it.´The first is that I don_t like the appearance of an empty item in the list (or somehow described  like "none") .

I have tried to use these properties with three blank value, but that does not seem to work. Have you tried this?  And if it would work it would be interesting to see, if I can use keyse kuje delete to empty the value.

Best regards

Thomas
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Thomas,
Basically it is a combination of handling your null value via the Business Object Mapper (BOM) and then setting the TopMostDescription and TopMostValue to the null value used in the BOM.

Ex:
  1. You have a string field value like CompanyName, in the BOM you set the "NULL Value Option" to "Return Alternate on Null" = String.Empty. So whenever a Null value is received from your database, the BO field value will have an empty string.
  2. In your ComboBox set the following properties:
    • TopMostDescription = <Select Company Name> or whatever text you want to show.
    • TopMostValue = "" leave it empty
  3. Now, when your data returns null or nothing, the combobox will show "Select Company Name" as the first item.
Same thing applies with Integers, just make sure the TopMostValue match with the BOM Null replacement value.

Edhy Rijo

StrataFrame Team
S
StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Everything Edhy said is right, Thomas.  But, if you don't like the appearance of the TopMostItem in the list, you can do something like handling the KeyDown on the combo and handle, say, F6 or something like that and when the user presses F6, set the SelectedValue of the combo box back to Nothing.  That will clear it out.  You'll have to teach your users to do this, maybe with a tooltip or something, but that or a small button next to the combo to set the SelectedValue back to Nothing are about your only options for clearing a combo box without having a "null" item at the top of the list.
Thomas Holste
Thomas Holste
StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)
Group: StrataFrame Users
Posts: 144, Visits: 618
Hi Ben,

I tried it and it does not work. This is what I put in the keydown-event of my combobox:



        If e.KeyCode = 46 Or e.KeyCode = 8 Then
            cmbwg.SelectedValue = Nothing
        End If


But I get an error:

****

Der Wert darf nicht NULL sein.
Parametername: key

****

Translated from German

*****

The value must not be NULL

*****

The stack trace is:

*****

Stack Trace:
   bei System.Windows.Forms.CurrencyManager.Find(PropertyDescriptor property, Object key, Boolean keepIndex)
   bei System.Windows.Forms.ListControl.set_SelectedValue(Object value)
   bei Gal2G.BestschnellFRM.cmbwg_KeyDown(Object sender, KeyEventArgs e) in D:\vb_net\Gal2GL\Gal2G\Gal2G\forms\BestschnellFRM.vb:Zeile 295.
   bei System.Windows.Forms.Control.OnKeyDown(KeyEventArgs e)
   bei System.Windows.Forms.ComboBox.OnKeyDown(KeyEventArgs e)
   bei System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m)
   bei System.Windows.Forms.ComboBox.ProcessKeyEventArgs(Message& m)
   bei System.Windows.Forms.Control.ProcessKeyMessage(Message& m)
   bei System.Windows.Forms.Control.WndProc(Message& m)
   bei System.Windows.Forms.ComboBox.WndProc(Message& m)
   bei MicroFour.StrataFrame.UI.Windows.Forms.ComboBox.WndProc(Message& m)
   bei System.Windows.Forms.Control.ControlNativewindow.OnMessage(Message& m)
   bei System.Windows.Forms.Control.ControlNativewindow.WndProc(Message& m)
   bei System.Windows.Forms.Nativewindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


What can I do?

Thanks and best regards

Thomas


 
StrataFrame Team
S
StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Will it let you set the SelectedIndex to -1?
Thomas Holste
Thomas Holste
StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)
Group: StrataFrame Users
Posts: 144, Visits: 618
Hi Ben,

that does not work either.  The error-message is:

*****

"!Ungültige Konvertierung von Typ DBNull in Typ String."

Translated:

"Invalid Conversion of Type DBNull to Type String.

*****

Best regards

Thomas
StrataFrame Team
S
StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
You need to alter the binding that SF creates to the combo box and change the DataSourceNullValue.  Like so:

Public Sub New()
        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        AddHandler Me.ComboBox1.DataBindings.CollectionChanged, AddressOf ComboBox1_BindingsChanged
    End Sub

    Private Sub ComboBox1_BindingsChanged(sender As Object, e As EventArgs)
        If Me.ComboBox1.DataBindings.Count > 0 AndAlso
            Me.ComboBox1.DataBindings(0).PropertyName = "SelectedValue" Then
            Me.ComboBox1.DataBindings(0).DataSourceNullValue = Nothing
        End If
    End Sub

Add the handler to the DataBindings.CollectionChanged event, then set the DataSourceNullValue property on the binding to either "Nothing" or "String.Empty", or whatever you want to use.  Silly .NET defaults it to DBNull.Value because they expect you to always bind to a DataRowView.  If you have more than 1 property bound on the ComboBox, then you'll need to find the one for SelectedValue within the collection to make sure you're setting the DataSourceNullValue on the right binding.
Thomas Holste
Thomas Holste
StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)
Group: StrataFrame Users
Posts: 144, Visits: 618
Hi Ben,

thanks a lot, a first test worked fine and I integrated it in my combobox-class.

Best regards

Thomas
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search