Skip to main content
Added a procedure for deleting elements
Source Link

Deleting a record is basically done so:

Sub listbox_delete
    Dim sValue as String
    Dim nItem As Integer
 
    '**Get the currently selected record
    nItem   = ReadControlValue(1)
    sValue  = listboxValues(nItem)    
    print "Deleting " & nItem & " = " & sValue

    '**Update the record in the query (and so in the base table)
    Delete From lstValues 
        Where ROWID = arrRecordRowIDs(nItem)

    '**Refresh the list in the dialog
    Call AlterMainDialog

End Sub

You might want to add a Ask() function to ask the user if he really want to delete the record. Also you need to add a button to the dialog that will call this procedure

Deleting a record is basically done so:

Sub listbox_delete
    Dim sValue as String
    Dim nItem As Integer
 
    '**Get the currently selected record
    nItem   = ReadControlValue(1)
    sValue  = listboxValues(nItem)    
    print "Deleting " & nItem & " = " & sValue

    '**Update the record in the query (and so in the base table)
    Delete From lstValues 
        Where ROWID = arrRecordRowIDs(nItem)

    '**Refresh the list in the dialog
    Call AlterMainDialog

End Sub

You might want to add a Ask() function to ask the user if he really want to delete the record. Also you need to add a button to the dialog that will call this procedure

Source Link

Here are some suggestions:

At the top add another array variable to hold the rowids from the query you get your values from. Just add the last line. The first line helps you to see where to add it:

dim listboxValues() as string
dim arrRecordRowIDs() as Integer

You have to fill this array with the rowids of the records in the NodeList procedure:

 redim listboxValues(nrows)
 Redim arrRecordRowIDs(nrows)
 for i = 1 to tableinfo("lstValues",tab_info_nrows)
      fetch rec i from lstValues
      listboxValues(i)      = lstValues.lname
      arrRecordRowIDs(i)    = lstValues.ROWID
 Next

Next step is to change your current way to insert a new record slightly in the AddItemDialog procedure. Instead of calling AlterMainDialog when you have inserted the new record, you call editlistDialog to reload all the elements and create a new query. When you do this you donøt have to add the element to the array of values first. The reason for doing this is that you need to be able to update it later on, potentially, and you can only do this if the value is in the query:

If CommandInfo(CMD_INFO_DLG_OK) Then
    insert into subn (lname)
        values (strAddItem)     

    Call editlistDialog
End If

Now we need to get you listbox_edit procedure finished:

Sub listbox_edit
    Dim sValue as String
    Dim nItem As Integer
 
    If CommandInfo(CMD_INFO_DLG_DBL) = TRUE Then
        '**Get the currently selected record
        nItem   = ReadControlValue(1)
        sValue  = listboxValues(nItem)    
        print nItem & " = " & sValue

        '**Shop the value in the dialog and read what the user changed it to
        Dialog Title "Change Item Dialog"
            Control EditText Width 100 
                Value sValue 
                Into sValue
            Control OkButton 
                Title "Update" 
            Control CancelButton

        If CommandInfo(CMD_INFO_DLG_OK) Then
            '**Update the array
            listboxValues(nItem) = sValue

            '**Update the record in the query (and so in the base table)
            Update lstValues
                Set lname = sValue
                Where ROWID = arrRecordRowIDs(nItem)

            '**Refresh the list in the dialog
            Call AlterMainDialog
        End If
    End If

End Sub