Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Removing items in a listbox with a SQL source
Message
From
26/09/2003 11:48:27
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00832474
Message ID:
00832730
Views:
18
This message has been marked as a message which has helped to the initial question of the thread.
>Hi all,
>
>I'm building a work order form that has a listbox on a pageframe that is populated with a SQL statement so that the items related to that order are the items in the list box. The user needs to be able to remove items from the order. I'm having problems getting this to work. This code is in the click event of cmdRemoveItem.
>
>LOCAL cSelectedItem
>*** remove one item from this order
>cSelectedItem = thisform.pgfPuDlvDetails.pagstop1.lstOrderItems.Selected
>IF MESSAGEBOX("Are you sure you want to remove this item?", 292,;
>	    "Please confirm removing this item") = 6
>    IF cSelectedItem
>         thisform.pgfPuDlvDetails.pagstop1.lstOrderItems.RemoveItem
>    ENDIF
>ENDIF
>thisform.Refresh
>DODEFAULT()
>
>I've tried variations on this and can't seem to get it to work. After it does work I need to update the underlying table and run the query again so the form is refreshed with the revised data. Where am I missing the point?
>Using VFP8 with Codemine7.1 on W2Ksp4
>TIA

Matthew,
As I understand modeling this with testdata.dbc you'd remove the items from orditems ? ie :
Assuming there is an txtOrderID on form with an initial value=0
* txtOrderID.Valid
thisform.lstmyList.Requery()

* Listbox.init
With This
  .RowSourceType = 3 && SQL
  .RowSource = ;
    'Select pr.prod_name, oi.Quantity, oi.unit_price, '+;
    '  oi.line_no, o.cust_id, o.order_id '+;
    '  from orders o '+;
    '  inner Join orditems oi On o.order_id = oi.order_id '+;
    '  inner Join products pr On pr.product_ID = oi.product_ID '+;
    '  where Val(o.order_id) = Thisform.txtOrderID.Value '+;
    '  order By oi.line_no '+;
    '  into Cursor crsOItems'
  .ColumnCount = 4
  .ColumnWidths = "150,100,100,50"
  .MultiSelect = .T.
Endwith

* command button click
*Confirm deletion - assuming no buffer for simplicity
With Thisform.lstMyList
  Select crsOItems
  Scan For .Selected(Recno())
    Delete From ordItems ;
      where order_id = crsOItems.order_id And ;
            line_no = crsOItems.line_no
  Endscan
  .ListIndex=0
  .Requery
Endwith
PS: You could do this easier with Foxyclasses' MultiSelectGrid and Moverlist classes.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform