jgoemat Master Cheater
Reputation: 22
Joined: 25 Sep 2011 Posts: 260
|
Posted: Mon Jul 23, 2018 12:57 am Post subject: ListView Tutorial |
|
|
I was using ListView for a project and decided to write a tutorial:
https://wiki.cheatengine.org/index.php?title=Tutorial:LuaFormListView
It covers the basics, using OwnerData for performance, and custom styles. The sample shows a view of a million-row lua table. Here's the complete code-behind:
Code: | -- items
list = list or {}
if #list == 0 then
for i=1,1000000 do
local item = {
message = string.format('Message %d', i),
data = math.sqrt(i)
}
table.insert(list, item)
end
end
-- need to set the Items.Count property so that it knows how many rows there
-- are in total
UDF1.CEListView1.Items.Count = #list
-- definition created by double-clicking OnData event handler
function CEListView1Data(sender, listitem)
-- use + 1 because listitem.Index is 0-based
local d = list[listitem.Index + 1]
if not d then return end
listitem.Caption = d.message -- first column
-- other columns have sqrt of data property and CURRENT clock
-- when this event was called
local others = {string.format('%0.3f', math.sqrt(d.data)), os.clock()}
listitem.SubItems.text = table.concat(others, '\n')
end
function CEListView1CustomDrawSubItem(Sender, Item, SubItem, State)
if (Item.Index % 2) == 1 then
Sender.Canvas.Brush.Color = 0xffe0e0 -- odd rows blue bg (0-based)
if SubItem == 1 then Sender.Canvas.Font.Color = 0x8f8f8f end -- gray middle column
else
Sender.Canvas.Brush.Color = 0xffffff -- odd rows white bg (0-based)
if SubItem == 2 then
Sender.Canvas.Font.Color = 0xffff40 -- cyan right column
else
Sender.Canvas.Font.Color = 0x2020ff -- red other columns
end
end
return true -- return true for DefaultDraw
end
function CEListView1CustomDrawItem(Sender, Item, State)
return CEListView1CustomDrawSubItem(Sender, Item, 0, State)
end |
I'm going to handle selecting and handling user events later...
Description: |
|
Filesize: |
12.73 KB |
Viewed: |
5493 Time(s) |

|
|
|