View previous topic :: View next topic |
Author |
Message |
cancandodo Advanced Cheater Reputation: 0
Joined: 09 Mar 2012 Posts: 62
|
Posted: Sat Dec 08, 2018 5:39 pm Post subject: how to search and jmp to the rhigt line of listbox by text? |
|
|
i need to write some text in ceedit
and when i click the "search" button,the jmp to the line of the listbox
Description: |
|
Filesize: |
25.21 KB |
Viewed: |
1801 Time(s) |
|
|
|
Back to top |
|
|
FreeER Grandmaster Cheater Supreme Reputation: 53
Joined: 09 Aug 2013 Posts: 1091
|
Posted: Sun Dec 09, 2018 2:37 pm Post subject: |
|
|
from celua.txt
Code: | ListBox Class: (Inheritance: WinControl->Control->Component->Object)
createListBox(owner): Creates a ListBox class object which belongs to the given owner. Owner can be any object inherited from WinControl
properties
MultiSelect: boolean - When set to true you can select multiple items
Items: Strings - Strings derived object containings all the items in the list <------------------
Selected[] - Returns true if the given line is selected. Use Items.Count-1 to find out the max index
ItemIndex: integer - Get selected index. -1 is nothing selected <------------------ presumably can set it as well
Canvas: Canvas - The canvas object used to render on the object
methods
clear()
clearSelection() : Deselects all items in the list
selectAll(): Selects all items in the list
getItems(): Returns a strings object <------------------ alternative
setItems(Strings): sets a strings object to the listbox
getItemIndex()
setItemIndex(integer) <------------------ alternative
getCanvas()
|
Code: | Strings Class: (Inheritance : Object) (Mostly an abstract class)
properties
LineBreak: String - the character(s) to count as a linebreak
Text : String - All the strings in one string
Count: Integer - The number of strings in this list
String[]: String - Array to access one specific string in the list
[] = String[]
methods
clear() : Deletes all strings in the list
add(string) : adds a string to the list
delete(index) : Deletes a string from the list
getText() : Returns all the strings as one big string
setText() : Sets the strings of the given strings object to the given text (can be multiline)
indexOf(string): Returns the index of the specified string. Returns -1 if not found <------------------
insert(index, string): Inserts a string at a specific spot moving the items after it
getCount(): Returns the number is strings in the list
remove(string); Removes the given string from the list
loadFromFile(filename) : Load the strings from a textfile
saveToFile(filename) : Save the strings to a textfile
getString(index) : gets the string at the given index
setString(index, string) : Replaces the string at the given index
beginUpdate() : Stops updates from triggering other events (prevents flashing)
endUpdate(): call after beginUpdate
|
listbox.ItemIndex = listbox.Items.indexOf(ceedit.Text)
_________________
|
|
Back to top |
|
|
cancandodo Advanced Cheater Reputation: 0
Joined: 09 Mar 2012 Posts: 62
|
Posted: Mon Dec 10, 2018 12:49 am Post subject: |
|
|
FreeER wrote: |
listbox.ItemIndex = listbox.Items.indexOf(ceedit.Text) |
it work correct!tks!!!
but this code have a problem
i must type full items'name,for e.x
type kobe→jump to the line "kobe" success
but i type "ko"or"be",→cannot jump
|
|
Back to top |
|
|
FreeER Grandmaster Cheater Supreme Reputation: 53
Joined: 09 Aug 2013 Posts: 1091
|
Posted: Mon Dec 10, 2018 8:31 am Post subject: |
|
|
yep. For partial I suppose you could do something like
Code: |
local first_match = true -- config to jump to first partial match or only unique matches
local partial = ceedit.text
local items = listbox.Items
local matches = {}
for i=0, items.Count-1 do
if items[i]:match(partial) then
matches[#matches+1] = i
end
end
if #matches >0 and (first_match or #matches == 1) then
listbox.ItemIndex = matches[1]
end
|
_________________
|
|
Back to top |
|
|
cancandodo Advanced Cheater Reputation: 0
Joined: 09 Mar 2012 Posts: 62
|
Posted: Sat Feb 02, 2019 10:03 pm Post subject: |
|
|
FreeER wrote: | yep. For partial I suppose you could do something like
Code: |
local first_match = true -- config to jump to first partial match or only unique matches
local partial = ceedit.text
local items = listbox.Items
local matches = {}
for i=0, items.Count-1 do
if items[i]:match(partial) then
matches[#matches+1] = i
end
end
if #matches >0 and (first_match or #matches == 1) then
listbox.ItemIndex = matches[1]
end
|
|
tks,but this code just jump the first result in the list,can not jump to the next line when i click the seach button
for ex
items of listbox is
kobe
o''neal
Jordan
LeBronJames
James Harden
when i type text "James" in ceedit,
then click the "jump" button
it only jump to the "LeBronJames" line
can not jump to the "James Harden" line ,
No matter how many times i click the botton
|
|
Back to top |
|
|
|