Home | Free Lite Version | Buy Now | Free Bonuses | Free Stuff | Links



Popup Multi-Column ListBox Dialog

The xDialog Multi-Column ListBox dialog lets you display a multi-column list box of items to select from. It can be used for simple lists with a few items or large lists with thousands of items. Items can be hard coded in, loaded from a Lua table, a text file or an SQLite database.

You can set the title, the number of columns, the column titles, the column widths, the column value to return, the width and the height. The list can be sorted by any column by clicking the column header. See the example code below.

Download Demo Application to see it in action.

 

These examples assume that the xDialog functions have been added to the Global functions. You can easily do this using the Add Code button on the Script Editor.

Example 1


-- This example returns the value of one column from the selected row

-- Clear input fields
Input.SetText("name", "")
Input.SetText("address", "")
Input.SetText("city", "")
Input.SetText("phone", "")

-- Set column titles in the first row
-- Row must end in a "|"
-- Columns must be seperated by a ";"
-- You can also optionally set the column widths by adding the width as a number and  a "~" before the name
Rows = "0~ID;150~Name;150~Address;100~City;90~Phone;|"

-- Add additional rows
-- Each row must end in a "|"
-- Column values must be separated by a ";"
Rows = Rows .. "1;John Smith;542 Oak Street;Vancouver;604-852-9512;|"
Rows = Rows .. "2;Paul Murray;1002 Main Street;Vancouver;604-777-1232;|"
Rows = Rows .. "3;Brian Jenson;1578 108th Ave.;Surrey;604-752-9322;|"
Rows = Rows .. "4;Casey Brown;35 No. 3 Road;Richmond;604-622-9541;|"
Rows = Rows .. "5;Tammy White;2567 Lonsdale Ave.;North Vancouver;604-852-9512;|"
Rows = Rows .. "6;Robert Grey;29 Hastings Street;Burnaby;604-258-9541;|"
Rows = Rows .. "7;Timothy Rogers;1155 Nelson Ave.;Coquitlam;604-632-5326;|"
Rows = Rows .. "8;Mandy Cooper;3256 Ioco Road;Port Moody;604-552-5421;|"

-- Set the column value to return. Use -1 to return all columns
nReturnCol = 2

-- Display the listbox
result = xDialog.Show_MultiColumn_ListBox("Select a customer", Rows, nReturnCol, 515, 515)

-- If the Cancel button was not clicked, then set the input object to the value returned.
if result ~= "CANCEL" then
   Input.SetText("name", result)
end

 


Example 2


-- This example returns the value of all columns from the selected row

-- Thus function is used to sperate the values from the return string
function DelimitedStringToTable(DelimitedString, Delimiter)

   
tbReturn = {}
   
local strWorking
   
local nPos = nil
   
local strData
   
local nTableIndex = 1
   
local nDelimiterLength = String.Length(Delimiter)
   
   if(nDelimiterLength < 1)then
      tbReturn[nTableIndex] = DelimitedString
      return tbReturn
   
end
   
   strWorking = DelimitedString
   nPos = String.Find(strWorking, Delimiter)

   while(nPos ~= -1)do
      strData = String.Left(strWorking, nPos -1)
      tbReturn[nTableIndex] = strData
      nTableIndex = nTableIndex + 1
      local nLength = String.Length(strWorking)
      strWorking = String.Right(strWorking, nLength - (nPos + (nDelimiterLength -1)))
      nPos = String.Find(strWorkingDelimiter)
   end

   if(strWorking ~= "")then
      tbReturn[nTableIndex] = strWorking
   
end
   
   
return tbReturn
end

------------------------------------------------------------------------------------------------

-- Clear input fields
Input.SetText("name", "")
Input.SetText("address", "")
Input.SetText("city", "")
Input.SetText("phone", "")

-- Set column titles in the first row
-- Row must end in a "|"
-- Columns must be seperated by a ";"
-- You can also optionally set the column widths by adding the width as a number and  a "~" before the anme
-- We will hide the first column by setting its width to 0
Rows = "0~ID;150~Name;150~Address;100~City;90~Phone;|"

-- Add additional rows
-- Each row must end in a "|"
-- Column values must be seperated by a ";"
Rows = Rows .. "1;John Smith;542 Oak Street;Vancouver;604-852-9512;|"
Rows = Rows .. "2;Paul Murray;1002 Main Street;Vancouver;604-777-1232;|"
Rows = Rows .. "3;Brian Jenson;1578 108th Ave.;Surrey;604-752-9322;|"
Rows = Rows .. "4;Casey Brown;35 No. 3 Road;Richmond;604-622-9541;|"
Rows = Rows .. "5;Tammy White;2567 Lonsdale Ave.;North Vancouver;604-852-9512;|"
Rows = Rows .. "6;Robert Grey;29 Hastings Street;Burnaby;604-258-9541;|"
Rows = Rows .. "7;Timothy Rogers;1155 Nelson Ave.;Coquitlam;604-632-5326;|"
Rows = Rows .. "8;Mandy Cooperh;3256 Ioco Road;Port Moody;604-552-5421;|"

-- Set the column value to return. Use -1 to return all columns
nReturnCol = -1

-- Display the listbox
result = xDialog.Show_MultiColumn_ListBox("Select a customer", Rows, nReturnCol, 515, 515)

-- If the Cancel button was not clicked, then set the input object to the value returned.
if result ~= "CANCEL" then

      -- Use the DelimitedStringToTable function to seperate the values returned. The values will be delimited by "|"
   tItems = DelimitedStringToTable(result, "|")
   
   if tItems and Table.Count(tItems) > 0 then
      -- Loop through the table and get the column values.
      -- Because the first column was hidden (width set to 0) we start at number 2

      for n = 2, Table.Count(tItems) do
         if n == 2 then
            Input.SetText("name", tItems[n])
         elseif n == 3 then
            Input.SetText("address", tItems[n])
         elseif n == 4 then
            Input.SetText("city", tItems[n])
         elseif n == 5 then
            Input.SetText("phone", tItems[n])
         end
      end
   end
end

 

Copyright © 2007 All Rights Reserved