FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Deleting items from ListBox

 
Post new topic   Reply to topic     Forum Index -> DFL
View previous topic :: View next topic  
Author Message
mpdeimos



Joined: 26 Jan 2009
Posts: 3
Location: Munich / Bavaria

PostPosted: Sun Feb 15, 2009 3:41 pm    Post subject: Deleting items from ListBox Reply with quote

hey, first of all keep up the great work with DFL and Entice!

But now to my problem: I need to edit and delete items from a listbox shown below.
using myListBox.items[0] = "bla"; doesn't work Sad



Thx for the help
Back to top
View user's profile Send private message
ideage



Joined: 12 Jul 2006
Posts: 63
Location: china

PostPosted: Mon Feb 16, 2009 4:18 am    Post subject: Reply with quote

try ListString object.
Code:

Object selItem;
selItem = lbox.selectedItem;
lbox.items.remove(selItem);            
selItem = new ListString("Ah");
lbox.items.add(selItem);



or use opIndexAssign,the function will delete,then insert.

Code:
lbox.items.opIndexAssign(new ListString("Ah"),1);

________
VAPORIZER WIKI


Last edited by ideage on Tue Mar 15, 2011 2:48 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
mpdeimos



Joined: 26 Jan 2009
Posts: 3
Location: Munich / Bavaria

PostPosted: Mon Feb 16, 2009 5:05 am    Post subject: Reply with quote

thanks this works.
but i still have 2 questions:
1) Should items.opIndexAssign("foo", i) not do the same as items[i] = "foo" ?

2) from the ObjectCollection implementation i just don't see the remove and opIndexAssign operations and there is no inheritance Sad

Code:

   static class ObjectCollection
   {
      protected this(ListBox lbox)
      {
         this.lbox = lbox;
      }
      
      
      protected this(ListBox lbox, Object[] range)
      {
         this.lbox = lbox;
         addRange(range);
      }
      
      
      protected this(ListBox lbox, Dstring[] range)
      {
         this.lbox = lbox;
         addRange(range);
      }
      
      
      /+
      protected this(ListBox lbox, ObjectCollection range)
      {
         this.lbox = lbox;
         addRange(range);
      }
      +/
      
      
      void add(Object value)
      {
         add2(value);
      }
      
      
      void add(Dstring value)
      {
         add(new ListString(value));
      }
      
      
      void addRange(Object[] range)
      {
         if(lbox.sorted)
         {
            foreach(Object value; range)
            {
               add(value);
            }
         }
         else
         {
            _wraparray.addRange(range);
         }
      }
      
      
      void addRange(Dstring[] range)
      {
         foreach(Dstring value; range)
         {
            add(value);
         }
      }
      
      
      private:
      
      ListBox lbox;
      Object[] _items;
      
      
      LRESULT insert2(WPARAM idx, Dstring val)
      {
         insert(idx, val);
         return idx;
      }
      
      
      LRESULT add2(Object val)
      {
         int i;
         if(lbox.sorted)
         {
            for(i = 0; i != _items.length; i++)
            {
               if(val < _items[i])
                  break;
            }
         }
         else
         {
            i = _items.length;
         }
         
         insert(i, val);
         
         return i;
      }
      
      
      LRESULT add2(Dstring val)
      {
         return add2(new ListString(val));
      }
      
      
      void _added(size_t idx, Object val)
      {
         if(lbox.created)
         {
            if(dfl.internal.utf.useUnicode)
               lbox.prevwproc(LB_INSERTSTRING, idx, cast(LPARAM)dfl.internal.utf.toUnicodez(getObjectString(val)));
            else
               lbox.prevwproc(LB_INSERTSTRING, idx, cast(LPARAM)dfl.internal.utf.toAnsiz(getObjectString(val))); // Can this be unsafeAnsiz()?
         }
      }
      
      
      void _removed(size_t idx, Object val)
      {
         if(size_t.max == idx) // Clear all.
         {
            if(lbox.created)
            {
               lbox.prevwproc(LB_RESETCONTENT, 0, 0);
            }
         }
         else
         {
            if(lbox.created)
            {
               lbox.prevwproc(LB_DELETESTRING, cast(WPARAM)idx, 0);
            }
         }
      }
      
      
      public:
      
      mixin ListWrapArray!(Object, _items,
         _blankListCallback!(Object), _added,
         _blankListCallback!(Object), _removed,
         true, false, false) _wraparray;
   }
Back to top
View user's profile Send private message
ideage



Joined: 12 Jul 2006
Posts: 63
Location: china

PostPosted: Mon Feb 16, 2009 5:38 am    Post subject: Reply with quote

1): in D Programming Language Standard same. but only use opIndexAssign to work.

2):opIndexAssign method in module dfl.collections, it use mixin add the method.

mixin ListWrapArray!(Object, _items,
_blankListCallback!(Object), _added,
_blankListCallback!(Object), _removed,
true, false, false) _wraparray;
________
Yamaha RD400


Last edited by ideage on Wed Feb 02, 2011 5:11 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
mpdeimos



Joined: 26 Jan 2009
Posts: 3
Location: Munich / Bavaria

PostPosted: Mon Feb 16, 2009 5:48 am    Post subject: Reply with quote

k, so it was the mixin's fault why i havn't found the stuff whilest looking through the api and not finding any remove / alter ops.

thanks for sheding light in the dark
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DFL All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group