Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Populating List Control with preset index and ID
Message
De
11/06/2005 16:27:03
 
 
À
11/06/2005 11:39:13
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01022452
Message ID:
01022511
Vues:
11
Hi Cetin,

Thanks for the response. Wow, that is a lot of code! I was hoping for something simpler, < g > I guess I could query into an array in the current order. Then when the user reorders things, use the itemindex to replace the sortorder field in the table. I'll play around some more.

Thanks,

Ken

>>Hi,
>>
>>Is it possible to populate a list control with preset index AND id values?
>>
>>What I am trying to accomplish is allow the user to adjust the sorting order for a list if items. That sort order is used to set the order an item appears on reports.
>>
>>So, if I have a table that has fields item_ID I, descript C(40) and sortorder I,
>>
>>I want to populate the list control so thst the descript is listed and the item_ID is used as the lineitemid and the sortorder is used as the lineindex. Then, with the mover property set to .T., the user can adjust the lineindex and therefore (with some code in the valid method) the table sortorder.
>>
>>It appears from the help file that I can use additem with an index parameter OR I can use the addlineitem with a lineitemID parameter. But I want both!!
>>
>>Thanks,
>>
>>Ken
>
>Ken,
>You could do that easily if you selected into an array and used array as your rowsource. You don't need the index, _itemID already serves as a PK, right? Let the user sort and then in your table set sortindex loacting with _itemId (also there is ItemIdToIndex,IndexToItemId).
>However I prefer grids for such things. ie:
>
>oForm = Createobject('myForm')
>oForm.Show
>Read Events
>
>Define Class myForm As Form
>  DataSession = 2
>  Width = 450
>  Height = 320
>
>  Procedure Init
>    This.Newobject('myGrid1','mySorterGrid1','','','crsTest')
>    With This.myGrid1
>      .Top = 10
>      .Left = 25
>      .Width = 400
>      .Height = 300
>      .Visible = .T.
>    Endwith
>  Endproc
>
>  Procedure Load
>    Select  cust_id, company,contact, ;
>      0x7FFFFFFF As sorter, 0x7FFFFFFF As original ;
>      from customer ;
>      order By cust_id ;
>      into Cursor crsTest ;
>      readwrite
>    Replace All sorter With Recno(), original With Recno()
>    Index On sorter Tag sorter
>  Endproc
>
>  Procedure QueryUnload
>    Clear Events
>  Endproc
>Enddefine
>
>Define Class myGrid As Grid
>  DeleteMark = .F.
>  ReadOnly = .T.
>  RecordMark = .F.
>  ScrollBars = 3
>  SplitBar = .F.
>  Highlight = .F.
>  HighlightRow = .F.
>  Name = "grdMyGrid"
>
>  Procedure AddColumn
>    Lparameters nIndex, cAlias, cField
>    Nodefault
>    Local lcColName
>    lcColName = "clm"+cField
>    This.AddObject(m.lcColName,"myColumn", cAlias+"."+cField,nIndex)
>    With Evaluate('this.'+m.lcColName)
>      .Header1.Caption = m.cField
>    Endwith
>  Endproc
>
>  Procedure Init
>    Lparameters tcRecordsource
>    With This
>      .ColumnCount = -1
>      .RecordSource = tcRecordsource
>      nOldColCount = .ColumnCount
>      For ix = 1 To Fcount(tcRecordsource)
>        .AddColumn(ix, tcRecordsource,Field(ix,tcRecordsource))
>      Endfor
>      .ColumnCount = nOldColCount
>    Endwith
>  Endproc
>
>  Procedure MyDragDrop
>    Lparameters oSource, nXCoord, nYCoord, nState
>    Local lnFrom, lnTo
>    With This
>      nXCoord_In = Mcol(Wontop(),3)
>      nYCoord_In = Mrow(Wontop(),3)
>      Store 0 To nWhere_Out , nRelRow_Out , nRelCol_Out , nView_Out
>      If .GridHitTest(nXCoord_In, nYCoord_In, ;
>          @nWhere_Out, @nRelRow_Out, @nRelCol_Out) And nWhere_Out = 3
>        lnFrom = Recno()
>        .ActivateCell(nRelRow_Out, nRelCol_Out)
>        lnTo = Recno()
>        .MoveRecord(lnFrom,lnTo)
>      Endif
>    Endwith
>  Endproc
>
>  Procedure MoveRecord
>    Lparameters tnFrom, tnTo
>    If tnFrom = tnTo
>      Return
>    Endif
>    Local lnFrom, lnTo
>    Select (This.RecordSource)
>    Go tnTo
>    lnTo = sorter
>    Go tnFrom
>    lnFrom = sorter
>    If lnTo < lnFrom
>      Replace sorter With sorter+1 For Between(sorter,lnTo,lnFrom-1)
>    Else
>      Replace sorter With sorter-1 For Between(sorter,lnFrom+1,lnTo)
>    Endif
>    Go tnFrom
>    Replace sorter With lnTo
>    This.Refresh
>  Endproc
>Enddefine
>
>Define Class mySorterGrid1 As myGrid
>  Name = "grdMyGrid"
>
>  Procedure DragDrop
>    Lparameters oSource, nXCoord, nYCoord, nState
>    This.MyDragDrop(oSource, nXCoord, nYCoord, nState)
>  Endproc
>Enddefine
>
>Define Class mySorterGrid2 As myGrid
>  Name = "grdMyGrid"
>
>  Procedure DragOver
>    Lparameters oSource, nXCoord, nYCoord, nState
>    This.MyDragDrop(oSource, nXCoord, nYCoord, nState)
>  Endproc
>Enddefine
>
>Define Class myColumn As Column
>  Resizable = .F.
>  Movable = .F.
>  Procedure Init
>    Lparameters cControlSource, nIndex
>    With This
>      .ControlSource = cControlSource
>      .ColumnOrder = nIndex
>      .AddObject("myText","myGridTxtBox")
>      .CurrentControl = "myText"
>      .Sparse = .F.
>    Endwith
>  Endproc
>Enddefine
>
>Define Class myGridTxtBox As TextBox
>  Name = "Text1"
>  BorderStyle = 0
>
>  Procedure MouseDown
>    Lparameters nButton, nShift, nXCoord, nYCoord
>    If nButton=1
>      nStart=Seconds()
>      Do While Mdown() And Seconds() - nStart < 1
>        If Seconds() - nStart > 0.8
>          This.Drag(1)
>          Exit
>        Endif
>      Enddo
>    Endif
>  Endproc
>Enddefine
>
PS: Drag is designed to start if button is held down at least 0.8secs.
>Cetin
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform