CodeCharge Studio All ASP PHP Perl ColdFusion Java C#.NET VB.NET

Dynamically Modify the "List Of Values" of a ListBox

The values in a List Box control can be specified by using a list of values which appear in pairs. Each entry in a List Box is composed of a value which is displayed and another which is submitted, hence the pairs. Using event code, you can specify the pairs that will make up the entries of the ListBox.

In this example, we have a Status List Box which is located in a Tasks Record form.

  1. Select ListOfValues in the Source Type property of the List Box.
  2. In the Before Show event to the Record form, add the custom code shown below:

ASP

Function Tasks_BeforeShow(Sender) 
  
  Set Tasks.Status.DataSource = CCCreateDataSource(dsListOfValues, Empty, _
      Array(Array("1","2","3"),Array("High","Normal","Low")))

End Function

PHP

function Tasks_BeforeShow(& $sender) {
  global $Tasks;
 
  $Tasks->Status->Values = array(array("1", "High"),array("2", "Normal"), array("3", "Low"));

}

Perl

sub Tasks_BeforeShow() {

  $Tasks->{Status}->{Values} = [["1", "High"],["2", "Normal"], ["3", "Low"]];
 
}

ColdFusion

<!--Tasks_BeforeShow --->

  <CFSET arr_tasksStatus=ListToArray("1;High;2;Normal;3;Low",";")>
 

VB.Net

'Tasks_BeforeShow

  item.statusItems.Clear()
  tasksstatus.Items.Clear()
  item.statusItems.Add("","Select Value")
  item.statusItems.Add("1", "High")
  item.statusItems.Add("2", "Normal")
  item.statusItems.Add("3", "Low")
  item.statusItems.CopyTo(tasksstatus.Items)
 

C#

//Tasks_BeforeShow

  item.statusItems.Clear();
  tasksstatus.Items.Clear();
  item.statusItems.Add("","Select Value");
  item.statusItems.Add("1", "High");
  item.statusItems.Add("2", "Normal");
  item.statusItems.Add("3", "Low");
  item.statusItems.CopyTo(tasksstatus.Items);
 

Java

//Tasks_BeforeShow

  e.getRecord().getList("status").setListOfValues("1;High;2;Normal;3;Low");

See Also:

Before Show event


On-line, printable versions and updates