Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Using a listview (object with columns) and setProperty

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Tutorials -> LUA Tutorials
View previous topic :: View next topic  
Author Message
Dark Byte
Site Admin
Reputation: 468

Joined: 09 May 2003
Posts: 25719
Location: The netherlands

PostPosted: Thu Jul 07, 2011 3:47 pm    Post subject: Using a listview (object with columns) and setProperty Reply with quote

a listview is an object that will usually be used for display data ordered in columns (depending on the viewstyle)

Also, sometimes a component has properties you want to access but they are only available to the designer. If for some reason you do not wish to use the designer, but do want access to those properties, you can use the setProperty function.
In this example I use it to access 3 properties not exported specifically to the lua script engine


This example creates a listview with 3 columns and 3 rows
This is just a blunt example, the variable usage can be done a lot smarter, but just showing the easy way for starters


warning: this code is obsolete

Code:

f=createForm()
lv=createListView(f)
setProperty(lv, 'ViewStyle', 'vsReport') --non lua exported property but you can access it with this
setProperty(lv, 'RowSelect', 'True')
setProperty(lv, 'ReadOnly', 'True')
lvc=listview_getColumns(lv)
column1=listcolumns_add(lvc)
column2=listcolumns_add(lvc)
column3=listcolumns_add(lvc)

listcolumn_setCaption(column1, 'a')
listcolumn_setCaption(column2, 'b')
listcolumn_setCaption(column3, 'c')

lvi=listview_getItems(lv);
row1=listitems_add(lvi)
listitem_setCaption(row1, 'Row 1'); --rw 1 column a
row1_subitems=listitem_getSubItems(row1) --returns a Strings object
strings_add(row1_subitems, 'r1_cb') --row 1 column b
strings_add(row1_subitems, 'r1_cc') --row 1 column c


row2=listitems_add(lvi)
listitem_setCaption(row2, 'Row 2');
row2_subitems=listitem_getSubItems(row2)
strings_add(row2_subitems, 'r2_cb')
strings_add(row2_subitems, 'r2_cc')


row3=listitems_add(lvi)
listitem_setCaption(row3, 'Row 3');
row3_subitems=listitem_getSubItems(row3)
strings_add(row3_subitems, 'r3_cb')
strings_add(row3_subitems, 'r3_cc')

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping


Last edited by Dark Byte on Tue Jun 11, 2024 11:14 pm; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
happyreadygo
Advanced Cheater
Reputation: 1

Joined: 14 Sep 2011
Posts: 87

PostPosted: Fri Sep 28, 2012 4:41 am    Post subject: Reply with quote

I am new to listview .

this code from your example.
Code:
lvi=listview_getItems(lv);
row1=listitems_add(lvi)
listitem_setCaption(row1, 'Row 1'); --rw 1 column a
row1_subitems=listitem_getSubItems(row1) --returns a Strings object
strings_add(row1_subitems, 'r1_cb') --row 1 column b
strings_add(row1_subitems, 'r1_cc') --row 1 column c


why this code is not like this?

Code:
lvi=listview_getItems(lv);
row1=listitems_add(lvi)
row1_subitems=listitem_getSubItems(row1) --returns a Strings object
strings_add(row1_subitems, 'Row 1') --row 1 column a
strings_add(row1_subitems, 'r1_cb') --row 1 column b
strings_add(row1_subitems, 'r1_cc') --row 1 column c


The ladder seems more understandable for me , or I misunderstand anything ?

ps. how to set listview to display fit to the form , as it now , Only show 5.5 lines of row.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 204

Joined: 25 Jan 2006
Posts: 8581
Location: 127.0.0.1

PostPosted: Sat Sep 29, 2012 8:28 am    Post subject: Reply with quote

When adding items like this, think of the first column in the row as the parent. The caption of the first parent is different from the sub-items within the same row. You set the parents caption, then add sub-items to it as a string list.

You can adjust the width and height to the forms using:
Code:

local w,h = control_getSize( f );
control_setSize( lv, w, h );

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
happyreadygo
Advanced Cheater
Reputation: 1

Joined: 14 Sep 2011
Posts: 87

PostPosted: Sat Sep 29, 2012 9:12 am    Post subject: Reply with quote

Thank you

Wiccaan wrote:
When adding items like this, think of the first column in the row as the parent.


I try to think like that.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 36

Joined: 16 Feb 2017
Posts: 1499

PostPosted: Tue Jun 11, 2024 9:14 pm    Post subject: Reply with quote

Usage example created from archives;


Code:

if f2 then f2.Destroy() end

f2=createForm()
f2.Height=270
lv=createListView(f2)
setProperty(lv, 'ViewStyle', 'vsReport') --non lua exported property but you can access it with this
setProperty(lv, 'RowSelect', 'True')
setProperty(lv, 'ReadOnly', 'True')
lvc=listview_getColumns(lv)
column1=listcolumns_add(lvc)
column2=listcolumns_add(lvc)
column3=listcolumns_add(lvc)

listcolumn_setCaption(column1, 'Desc')
listcolumn_setCaption(column2, 'Address')
listcolumn_setCaption(column3, 'Value')

column1.Width=45
column2.Width=90
column3.Width=85

l1=createLabel(f2)
l1.Left=30 l1.Top=160
l2=createLabel(f2)
l2.Left=30 l2.Top=180

e1=createEdit(f2)
e1.Left=30 e1.Top=200

b1=createButton(f2)
b1.Left=120 b1.Top=199
b1.Caption="Enable"
b2=createButton(f2)
b2.Left=30 b2.Top=235
b2.Caption="Save"
b3=createButton(f2)
b3.Left=120 b3.Top=235
b3.Caption="Load"
-----------------------------------------------------------
------- add items:

function addLevelItem(idx, addr, val) -- 3 per ..
lvi=listview_getItems(lv);
rd = "row"..idx
--idx2 = tonumber(idx) + 1 -- 1..2..3..
rd=listitems_add(lvi)
-- desc:
listitem_setCaption(rd, "["..idx.."]") -- 0..1..2..
row1_subitems=listitem_getSubItems(rd)
-- address:
strings_add(row1_subitems, addr)
-- value:
strings_add(row1_subitems, val)
end

 for i=0, 10 do
   idx = i
   addr = "Addr_"..i
   val = "val_"..i
   addLevelItem(idx, addr, val)
 end


-----------------------------------------------------------
------- select line:
local changeIndex=0

lv.OnClick=function()
changeIndex = listview_getItemIndex(lv)
r1 = listview_getItems(lv)
item = listitems_getItem(r1, changeIndex)
subitems = listitem_getSubItems(item)

l2.caption="Index: "..changeIndex
l1.Caption="Desc: "..item.Caption.." - Address: "..subitems[0].." - Value: "..subitems[1]

end


-----------------------------------------------------------
------- change Value:

b1.OnClick=function()
  if e1.Text~="" then
    r1 = listview_getItems(lv)
    item = listitems_getItem(r1, changeIndex)
    subitems = listitem_getSubItems(item)
    subitems[1] = e1.Text -- Value ..
    l1.Caption="Desc: "..item.Caption.." - Address: "..subitems[0].." - Value: "..subitems[1]
  else
    showMessage("Please write a value in the box!")
  end
end

-----------------------------------------------------------
------- save option list:

local savedialog = createSaveDialog()
savedialog.Title = 'Save List'
savedialog.DefaultExt = '.txt'
savedialog.Filter = 'textfiles (*.txt)|*.txt'
savedialog.Options = '[ofOverwritePrompt, ofHideReadOnly, ofEnableSizing]'

b2.OnClick=function()
  local sd_result = savedialog.Execute()
  if not sd_result then return end

  local filename = savedialog.FileName
  if filename==nil or filename=='' then return end
local text = ""
--print(filename)
    local saveResult = fileExists(filename) or "true" or false
 if saveResult=="true" then

  for i=0, lv.Items.Count -1 do
    r1 = listview_getItems(lv)
    item = listitems_getItem(r1, i)
    subitems = listitem_getSubItems(item)
    text = text..item.Caption.."@@@"..subitems[0].."@@@"..subitems[1].."\n"
  end

  if filename then
    sl = createStringlist()
    sl.Text = text
    sl.saveToFile(filename)
    sl.destroy()
  end
 else
    showMessage('Could not save to file '..filename)
 end
end

-----------------------------------------------------------
------- load option list:

local opendialog = createOpenDialog()
opendialog.Title = 'Open List'
opendialog.DefaultExt = '.txt'
opendialog.Filter = 'textfiles (*.txt)|*.txt'
opendialog.Options = '[ofOverwritePrompt, ofHideReadOnly, ofEnableSizing]'

b3.OnClick=function()
  local od_result = opendialog.Execute()
  if not od_result then return end

  local filename = opendialog.FileName
  if filename==nil or filename=='' then return end

    local openResult = fileExists(filename) or "true" or false
 if openResult==true then

    sl = createStringlist()
    sl.loadFromFile(filename)

  for i=0, sl.Count -1 do
    r1 = listview_getItems(lv)
    item = listitems_getItem(r1, i)
    subitems = listitem_getSubItems(item)
    desc,s0,s1 = string.match(sl[i],"(.-)@@@(.-)@@@(.*)")
    item.Caption=desc
    subitems[0]=s0
    subitems[1]=s1
  end
 else
    showMessage('Could not open to file '..filename)
 end
end

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Tutorials -> LUA Tutorials 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
You cannot attach files in this forum
You cannot download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites