Finding the correct index to delete a listView item

Hello 

I modified one of the training course ListView examples to demo adding and removing list box entries from a tree.

I dont know how to find an index of the listview in order to delete it. My actively populated ListView Items needs to correspond to the entries in a Skip List but ( because I need to return this Skip list in a function). I tried deleting on the basis of a key but this wont work.

I would really like to be able to delete a ListView entry based on its string contents and not its index, that would solve my problems.

Here is my code using a delete on the basis of the key. Is there any helper functions I could use to make this work( and make it simpler):

DB pizzaDB = create "Pizza Box"
Skip CHOOSE_TYPEDMOD_GUI_moduleList = create //we never delete this list in GUI because the list is returned outside..
string dummyList[] = {}
string str
int   ItemIndex=0
DBE trvDBE = treeView (pizzaDB, 0, 300, 6)
below pizzaDB

lsvDBE = listView(pizzaDB, 0, 300, 10, dummyList)

void applyCHOOSE_TYPEDMOD_GUI_Add_cb(DBE theDB) {

        put(CHOOSE_TYPEDMOD_GUI_moduleList,ItemIndex,  get(trvDBE  ))
        string the_string = ""

    str    = get(trvDBE)
        insert(lsvDBE, 0, str,iconNone)
  
    ItemIndex=ItemIndex+1
    infoBox("+++ItemIndex")
}


void applyCHOOSE_TYPEDMOD_GUI_Remove_cb(DBE theDB) 
{

        if (ItemIndex>0)
    {

        str        = get(lsvDBE )

        int x=0
        int y =0 
            string the_string = ""
        string the_lstring = ""

        string name_to_be_filled = ""
            string the_key_number_str = ""
                
                for the_string  in CHOOSE_TYPEDMOD_GUI_moduleList do 
                {

                        if (the_string == str)
                        {
                                int key_number = (int key(CHOOSE_TYPEDMOD_GUI_moduleList))
        
                                infoBox("Removing")
                                infoBox(the_string)
                                the_key_number_str= key_number ""
                                infoBox(the_key_number_str)
                                delete (CHOOSE_TYPEDMOD_GUI_moduleList, key_number)
                                delete(lsvDBE , key_number)
            
                        break
                }     
      }
        

      ItemIndex=ItemIndex-1


      infoBox(ItemIndex "")
    }         
         
}

void applyCHOOSE_TYPEDMOD_GUI_RemoveAll_cb(DBE theDB)
{

        infoBox("Removing all Modules")
    empty(lsvDBE)
}


button( pizzaDB, "Add", applyCHOOSE_TYPEDMOD_GUI_Add_cb)
right pizzaDB 
button( pizzaDB, "Remove", applyCHOOSE_TYPEDMOD_GUI_Remove_cb)
right pizzaDB 
button( pizzaDB, "RemoveAll", applyCHOOSE_TYPEDMOD_GUI_RemoveAll_cb)
right pizzaDB 



realize (pizzaDB)
empty(lsvDBE)
insertColumn(lsvDBE, 0, "Object ID", 150, iconNone)
insert(trvDBE, "pizzas", iconFormal, iconFormal)
insert(trvDBE, "pizzas/Menu", iconFormal, iconFormal)
insert(trvDBE, "pizzas/Special", iconFormal, iconFormal)
insert(trvDBE, "pizzas/Meat", iconFormal, iconFormal)
insert(trvDBE, "pizzas/hawaii", iconFormal, iconFormal)
insert(trvDBE, "pizzas/italian", iconFormal, iconFormal)

show (pizzaDB)

 


MyDeveloerWorks - Wed May 10 10:17:12 EDT 2017

Re: Finding the correct index to delete a listView item
MyDeveloerWorks - Wed May 10 11:01:21 EDT 2017

I found in the reference manual a method from treeView:

bool exists(DBE treeView, string fullPath)

 

Is there anything similar for listView thats undocumented?

Re: Finding the correct index to delete a listView item
O.Wilkop - Thu May 11 04:45:52 EDT 2017

MyDeveloerWorks - Wed May 10 11:01:21 EDT 2017

I found in the reference manual a method from treeView:

bool exists(DBE treeView, string fullPath)

 

Is there anything similar for listView thats undocumented?

The only option I see is looping through all entries in the listview and checking the content manually. Remember that deleting or adding (depending on the position where you delete/add) items from/to the listview might invalidate the indices in your skiplist (because they shift in the DBE). See the below (untested) example function to delete the first entry with the given value from the listview:

 

bool deleteListViewEntry(DBE dbeListView, string szToDelete){
        int iIndex = 0
        for (iIndex = 0; iIndex < noElems(dbeListView); iIndex += 1)
        {
                string szEntry = get(dbeListView, iIndex);
                if(szEntry == szToDelete){
                        delete(dbeListView, iIndex);
                        return true;
                }
        }
        return false;
}

 

Re: Finding the correct index to delete a listView item
MyDeveloerWorks - Thu Jun 08 04:42:50 EDT 2017

O.Wilkop - Thu May 11 04:45:52 EDT 2017

The only option I see is looping through all entries in the listview and checking the content manually. Remember that deleting or adding (depending on the position where you delete/add) items from/to the listview might invalidate the indices in your skiplist (because they shift in the DBE). See the below (untested) example function to delete the first entry with the given value from the listview:

 

bool deleteListViewEntry(DBE dbeListView, string szToDelete){
        int iIndex = 0
        for (iIndex = 0; iIndex < noElems(dbeListView); iIndex += 1)
        {
                string szEntry = get(dbeListView, iIndex);
                if(szEntry == szToDelete){
                        delete(dbeListView, iIndex);
                        return true;
                }
        }
        return false;
}

 

Thank you Oliver for your valuable suggestion!

(...apologies for the late acknowledgement!)