Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Removing items in a listbox with a SQL source
Message
From
27/09/2003 04:50:27
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00832474
Message ID:
00832911
Views:
25
This message has been marked as the solution 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
>
>Thanks, This gives me more to think about. One of the other things that happens is that the items on an order belong to a customer. They are stored in the warehouse. As items are added to a work order their status is updated to 'assigned' so they cannot be added to another order, or added again to the same order. If I remove an item from the order not only do I need to update the order_items table to show that it is no longer on the item, but I also need to change the status in the items table to place the item 'in warehouse'.
>
>Using the code you suggest, am I still limited to the total number of characters in the rowsource property? It seems to be 255 characters using the property page.

Matthew,
Notice that in sample code it might already be over 255 (I didn't count:). The 255 limit is for literal strings. Otherwise a string variable can hold up to 16Mb. ie:

myVar = "assume this is over 255..." && Illegal
myVar = "this is less than or equal to 255..."+;
"this is less than or equal to 255..."+;
"this is less than or equal to 255..." && Legal

While setting properties in PEM sheet you're limited to 255. But if you do that in code as in the above sample limit doesn't apply.

Also notice that while we use only the first 4 columns in listbox display, cursor has more columns than that. Actually even if your list would show only 1 column you might have 255 columns in its RowSource. That's you might have as many more columns that you need to store info about (ie: cust_id, order_amt, to_name ...)

If you look closely a row in SQL cursor has a one-to-one relation to list listindex. That's Listindex = 1 and rec #1, 2 = rec #2 and so on. IOW with an SQL rowsourcetype you could think of listbox sort of grid.

Therefore in your SQL have as many columns as you want to store enough info about what to delete. If lstBox.selected(5) = .t. than it means record 5 in your SQL cursor (crsOITems in sample) is selected. Directly use alias.field to access necessary column info. ie: crsOITems.order_id.
Notice that listbox is only used to check if Selected(nRecno). We don't use list(nRow,nCol) or there is no bound column like thing to check the value. Directly using crsOITems for things like that.
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