Application Techniques



Using Choice Controls and Combo Boxes

How to use choice and combo box controls on a form.

About this technique

Details

Category

Java Client Techniques> Version 2 AWT-based controls

Description

You'll learn about:

You can run this technique code from:

NOTE   First make sure that database is running on your localhost SilverStream Server

Related reading

See the chapter on the Form Designer in the Tools Guide

Getting the value of a selected row in a choice control   Top of page

The following code uses getSelectedIndex() to get the index value of a currently selected row in the choice control cbCompanies. It then uses getRowText() to get the string value, and uses setText() to place this value in the text field fldChoiceRowText. It also gets the storage value using getRowValue() and places this value in fldChoiceRowValue.

This code is in the valueChanged event for the choice box chCompanies:

  // Get the index of the selected row  
  int index = chCompanies.getSelectedIndex(); 
   
  // Valid row selected?  
  if (index != -1)  
  {  
     // Yes, so get the display value of the selected row,  
     // and display this in fldChoiceRowText  
     fldChoiceRowText.setText(chCompanies.getRowText(index));    
   
     // Get the storage value of the selected row  
     Integer rowValue = (Integer) chCompanies.getRowValue(index); 
        
     // Display the storage value in fldChoiceRowValue  
     fldChoiceRowValue.setText(rowValue.toString());     
  } 

Notes about the code

Getting the value of a selected row in a combo box   Top of page

The following code uses the getText() method to get the string value of a selected row in a combo box control tcbCompanies. Then, using setText(), the code places the value in the text field fldComboRowText.

This code is in the valueChanged event for the combo box cbCompanies:

  // Get the display value of the selected row,  
  // and display this in fldComboRowText  
  fldComboRowText.setText(cbCompanies.getText()); 

Notes about the code






Copyright © 2000, SilverStream Software, Inc. All rights reserved.