Missing item from combo

jamie_pattison

Well-known member
Joined
Sep 9, 2008
Messages
116
Programming Experience
Beginner
I have a data entry windows form containing some textboxes and a combo box.

The combo list items are generated by calling a stored proc on a SQL server. The SQL is similar to

VB.NET:
Select * from table where [B]Item[/B]=1

Item in the above code is a bit type in sql so it returns only the items that are available by setting the value to true/false against the item value.

A user would load this form and enter their name in the textbox etc, select an item from the list i.e. pencil and save the form.

The issue i have is if the user selected an item (like a pencil) from the dropdown, saves the form and then pencil is then set to 0 (false) in the database table.

Next time the form loads it displays pencil as the text in the combo box (which is ok) but if another field is changed on the form the user cant save the form as the combo is highlighting for the user to select an item from the combo, when in should remain with pencil. If they select ruler then the form is saved but this erases the original value which i want to keep.

How could i work around this by allowing pencil to be disabled at the database but still available so that the user could save the form with the original value but not selectable in the combobox any further?

Thanks
 
Have the db return the full list of items all the time, and another field for the user saying whether the combo should be disabled or not.. it is the combo youre looking to disable, not the pencil (which is a one-time user choice by the sound of things)
 
cjard


Have the db return the full list of items all the time, and another field for the user saying whether the combo should be disabled or not.. it is the combo youre looking to disable, not the pencil (which is a one-time user choice by the sound of things)

I dont think thats what im after. An example is if they are selecting a pencil it is saved as a record which also includes other fields that are later filled by another department (cost, number of pencils given etc etc).

If they decide to not include pencils in the dropdown because employees are not allowed to order pencils any further then its disabled at the database so its no longer displayed for users to select. The problem is when a user opens a record which has pencil saved before it was disabled and then updates a field (pencil distributed to employee) then the record cant be updated as its expecting pencil in the combo and only the items listed in the combo can be selected.
 
I propose you have your stock table:

ItemID, Item, IsAvailable
1, Pencil, Y
2, Ruler, N

Your orders table:
Employee, ItemOrdered, QuantityGiven
Sam, 1, NULL


And pseudocode:
VB.NET:
'attach to an event that fires when the current item the user is looking at, changes
Sub Something(SomeArgs) Handles OrdersBindingSource.CurrentItemChanged
  Dim ro as DirectCast(DirectCast(OrdersBindingSource.Current, DataRowView).Row, OrdersDataRow)
  If ro.RowState = RowState.Unchanged and Not ro.IsItemOrderedNull() Then 
    'downloaded from db, itemordered is populated
    StockBindingList.ClearFilter() 'all items available in combo  
    OrderItemCombo.Enabled = False
  Else
    StockBindingList.Filter = "[IsAvailable] = 'Y'" 'not all items available in combo  
    OrderItemCombo.Enabled = True
  End If
End Sub

Might need some tweaks to the logic but changing what the combo shows dependent on what actions the user can take might be the best way out here
 
Back
Top