<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.cheatengine.org/index.php?action=history&amp;feed=atom&amp;title=Lua%3AClass%3AListview</id>
	<title>Lua:Class:Listview - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.cheatengine.org/index.php?action=history&amp;feed=atom&amp;title=Lua%3AClass%3AListview"/>
	<link rel="alternate" type="text/html" href="https://wiki.cheatengine.org/index.php?title=Lua:Class:Listview&amp;action=history"/>
	<updated>2026-05-18T16:41:14Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.32.0</generator>
	<entry>
		<id>https://wiki.cheatengine.org/index.php?title=Lua:Class:Listview&amp;diff=6078&amp;oldid=prev</id>
		<title>Jgoemat: Created page with 'I recently had occasion to use this creating an Upgrade editor for Shadow Warrior 2 for the great table by Zanzer...  I have a function that opens a form in LUA, clears the list …'</title>
		<link rel="alternate" type="text/html" href="https://wiki.cheatengine.org/index.php?title=Lua:Class:Listview&amp;diff=6078&amp;oldid=prev"/>
		<updated>2018-05-30T08:38:38Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;#039;I recently had occasion to use this creating an Upgrade editor for Shadow Warrior 2 for the great table by Zanzer...  I have a function that opens a form in LUA, clears the list …&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;I recently had occasion to use this creating an Upgrade editor for Shadow Warrior 2&lt;br /&gt;
for the great table by Zanzer...&lt;br /&gt;
&lt;br /&gt;
I have a function that opens a form in LUA, clears the list view items, and&lt;br /&gt;
listens for the user to click on an item:&lt;br /&gt;
&lt;br /&gt;
  local lv = FormEditUpgrade.listViewProperties&lt;br /&gt;
  lv.items.clear()&lt;br /&gt;
  lv.setOnClick(FormEditUpgrade_listViewProperties_OnClick)&lt;br /&gt;
&lt;br /&gt;
So the form defines the list view with 3 columns.  I changed the following properties&lt;br /&gt;
when designing the form:&lt;br /&gt;
&lt;br /&gt;
* ColumnClick = False - ??&lt;br /&gt;
* ReadOnly = True - don't allow edits directly in the table&lt;br /&gt;
* RowSelect = True - select a whole row when clicking&lt;br /&gt;
* ViewStyle = vsReport - shows multiple columns with headings&lt;br /&gt;
&lt;br /&gt;
When the last upgrade changes, I analyze the memory and create an array in LUA &lt;br /&gt;
of the attributes of that upgrade.  I then clear the items array on the list&lt;br /&gt;
view and recreate them.&lt;br /&gt;
&lt;br /&gt;
You can see here that ''item.Caption'' controls what is displayed&lt;br /&gt;
in the first column.  I set the other columns using ''SubItems.text''&lt;br /&gt;
by setting it to the values to put in those columns separated by CRLF.&lt;br /&gt;
SubItems is a 'Strings' object and there may be a better way to do that,&lt;br /&gt;
but this was easy enough for me.&lt;br /&gt;
&lt;br /&gt;
  local function LoadUpgrade(address)&lt;br /&gt;
    CURRENT_UPGRADE = Upgrade(address)&lt;br /&gt;
    local lv = FormEditUpgrade.listViewProperties&lt;br /&gt;
    local items = lv.items&lt;br /&gt;
    items.clear()&lt;br /&gt;
    for i,attr in ipairs(CURRENT_UPGRADE.attributes) do&lt;br /&gt;
      local item = items:add()&lt;br /&gt;
      item.Caption = attr.name&lt;br /&gt;
      item.SubItems.text = table.concat({ attr.value or 'nil', attr.type }, '\r\n')&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
When the user clicks on a row, I use ''ItemIndex'' and match it to&lt;br /&gt;
the attribute in my LUA array.  The SelectAttribute function handles&lt;br /&gt;
using 'inputQuery' to pop up a window for changing the value, changing&lt;br /&gt;
the value, and reloading the updated Upgrade.&lt;br /&gt;
&lt;br /&gt;
  local function FormEditUpgrade_listViewProperties_OnClick()&lt;br /&gt;
    if CURRENT_UPGRADE == nil or CURRENT_UPGRADE.attributes == nil or #CURRENT_UPGRADE.attributes == 0 then return end&lt;br /&gt;
    local lv = FormEditUpgrade.listViewProperties&lt;br /&gt;
    local selectedIndex = lv.ItemIndex&lt;br /&gt;
    if selectedIndex &amp;lt; 0 or selectedIndex &amp;gt;= #CURRENT_UPGRADE.attributes then return end&lt;br /&gt;
    SelectAttribute(CURRENT_UPGRADE.attributes[selectedIndex+1]) -- +1 for 1 based LUA&lt;br /&gt;
  end&lt;/div&gt;</summary>
		<author><name>Jgoemat</name></author>
		
	</entry>
</feed>