List View Examples

Example 1. Disable or enable a list view.

IF boolSelect == false         

{

    lvProducts.Disable()

}

ELSE

{

    lvProducts.Enable()

}

Note:

Example 2. Select the next record and display the column values.

The GetCurrentRowColumnValue method can be used to obtain information from the result set of the query.

Assume for this example that the List Query returns two columns: PRODUCT_ID, PRODUCT_NAME.

//Select the next record in the list view.

VarIndex = lvProducts.GetSelection() + 1

listview1.SetSelection(VarIndex)

 

//Check if a record is selected.

IF lvProducts.GetSelection() < 0

{

    Form.MessageBox("Error", "Empty list view", MB_OK)

}

ELSE

{

    //Get the PRODUCT_ID value of the record.

    edOrderID = lvProducts.GetCurrentRowColumnValue("PRODUCT_ID")

    //Get the PRODUCT_NAME value of the record

    edProductName = lvProducts.GetCurrentRowColumnValue("PRODUCT_NAME")

}

Note:

Example 3. Hide or show a list view.

IF boolShow == false           

{

    lvProducts.Hide()

}

ELSE

{

    lvProducts.Show()

}

Note:

Example 4. Refresh a list view.

lvProducts.Refresh()

Note:

Example 5. Set focus on the list view.

lvProducts.SetFocus()

Note:

Example 6. Set the sort order of the listview.

listview2.SetSortOrder("NAME DESC")

listview2.Refresh()

Note:

Example 7. Using the checkbox column property and its corresponding methods.

The image above displays a listview with a checkbox on each row to allow users to select multiple records from the list.

To create a listview with checkbox columns, you must have a table column that is either an integer or a boolean data type in your listview query. Then select the table column from the Check-box Column property once the List Query has been defined as shown below:

The expression to link to the “Deselect All” button is as follows:

listview2.DeselectAll()

Note:

 

The expression to link to the “Select All” button is as follows:

listview2.SelectAll()

Note:

Example 8. Using the “Selection – Allow Multiple” property and its corresponding methods.

This attribute allows multiple selection of the listview rows at runtime. Using GetSelection(), GetSelectionCount() and SetSelection() methods of the listview control, the user's multiple selections can be processed.

// Returns the first of the multiple selections

local.FirstSelection = listview1.GetSelection();

 

// Returns the number of rows selected

local.SelectRowCount = listview1.GetSelectedCount();

 

// Find all the selected items

local.Count = 0;

local.Index = local.FirstSelection;

WHILE(local.Count < local.SelectRowCount)

{

    IF(listview1.IsRowSelected(local.Index))

    {

        local.Count = local.Count + 1;

        // Make the row as the current selection

        listview1.SetSelection(local.Index);

        // Do something

        // ….

    }

    local.Index = local.Index + 1;

 }

Note:

Example 9. Changing the listview query

The query retrieving the listview records may be changed in BrightBuilder using the SetSql() method. If the query is parameterised, the parameter may also be changed using the SetSqlParam() method after the query has been defined.

listview1.SetSql("select * from TABLE1 where ID > ?");

listview1.SetSqlParam("Param1", local.Variable);

listview1.Refresh();

Note:

Example 10. Showing/hiding listview columns

listview1.ShowColumn(local.ColIndex, true);

listview1.ShowColumn(local.ColIndex, false);

Note:

Example 11. Inserting listview columns

This method will insert a column into a listview at a given index, and increment the subsequent indexes by 1.

listview1.InsertColumn(local.ColIndex, "Id", "ID", local.Format, local.Width, ALIGNMENT_LEFT);

Note:

Example 12. Removing listview columns

The first method will delete a column at a given index. The second will delete all columns in the listview.

listview1.DeleteColumn(local.ColIndex);

listview1.DeleteAllColumns();

Note: