Page 1 of 1

Listbox Control functions

PostPosted: Jun 22, 2004 @ 11:46pm
by redshift
There are some function i create to better uderstand the behaviour of the listbox.

Theses functions are the typical one used for dealing with a listbox, why not including them in the ppl ?
This could decrease the amount of code to write by the user again :-) (probably not all but at least some, renaming them as listbox_additem, ...)

Functions: AddItem, RemoveItem, ReplaceItem, Select, GetSelected, ClearList, Load from a list, load from a file.

Some more will follow probably.

Listbox Usage:


Load an item in a listbox:

func AddItem(listbox$, editbox$)
text$ = GetText(editbox$);
where$ = SendMessage(listbox$, LB_GETCOUNT, 0, 0);
SendMessage(listbox$, LB_ADDSTRING, where$, text$);
Return(true);
end;

AddItem(LISTBOX101$,EDIT105$);


Get current selected item from a listbox:

func GetSelItem(listbox$, editbox$)
where$ = SendMessage(listbox$, LB_GETCURSEL, 0, 0);
text$ = GetItem(listbox$, where$);
SetText(editbox$, text$);
Return(true);
end;

GetSelItem(LISTBOX101$,EDIT105$);


Delete an item from a listbox:

func DelItem(listbox$)
where$ = SendMessage(listbox$, LB_GETCURSEL, 0, 0);
SendMessage(listbox$, LB_DELETESTRING, where$, 0);
Return(true);
end;

DelItem(LISTBOX101$);


Update an item in a listbox:

func UpdateItem(listbox$, editbox$)
text$ = GetText(editbox$);
where$ = SendMessage(listbox$, LB_GETCURSEL, 0, 0);
SendMessage(listbox$, LB_DELETESTRING, where$, 0);
SendMessage(listbox$, LB_INSERTSTRING, where$, text$);
//SendMessage(listbox$, LB_SETCURSEL, where$, text$); ?? is that functionnal for a replace ??
Return(true);
end;

UpdateItem(LISTBOX101$,EDIT105$);


Select All item in list:

func SelAllItem(listbox$)
where$ = SendMessage(listbox$, LB_GETCOUNT, 0, 0);
i$=0;
Repeat
SendMessage(listbox$, LB_SETSEL, i$, i$);
i$++;
Until(i$>=where$);
SendMessage(listbox$, LB_SETSEL, 1, 0);
Return (true);
end;

SelAllItem(LISTBOX101$);


Load Listbox from a list:

func list_to_listbox(listbox$, list$)
i$=0;
scount$ = Count(list$);
while (i$ < scount$)
SendMessage(listbox$, LB_ADDSTRING, i$, list$);
Next(list$);
i$++;
end;
end;

list_to_listbox(LISTBOX101$, list$);


Clear listbox content:

func ClearList(listbox$)
SendMessage(listbox$, LB_RESETCONTENT, 0, 0);
end;

ClearList(LISTBOX101$);


Load Listbox from a file:

func file_to_listbox(listbox$, Filename$)
s$ = LoadStr(Filename$, i$);
List(slist$);
StrToList (s$, "\n", slist$);
i$=0;
scount$ = Count(slist$);
while (i$ < scount$)
SendMessage(listbox$, LB_ADDSTRING, i$, slist$);
Next(slist$);
i$++;
end;
end;

file_to_listbox(LISTBOX101$, "\\My Documents\\ListBox1.txt");

PostPosted: Jun 23, 2004 @ 4:01pm
by kornalius
Hi RedShift,

Thanx a lot for your great work. Is it possible for you put all these functions into a .ppl library for example ListLib.ppl and send it to me? I will include it in the Listbox.ppl library file.

Regards,
Kornalius

PostPosted: Jun 23, 2004 @ 4:26pm
by redshift

PostPosted: Jun 24, 2004 @ 12:58am
by redshift
Here are the combobox and the listbox functions libs.

Regards,