HOWTO: Clearing a Selection in an AFC UIChoice Control

Last reviewed: January 27, 1998
Article ID: Q179851
The information in this article applies to:
  • Microsoft Win32 Virtual Machine for Java
  • SDK for Java, versions 2.0, 2.01

SUMMARY

You can programmatically clear a UIChoice selection by setting its selected index to -1.

MORE INFORMATION

The sample code below demonstrates how to use setSelectedIndex(-1) to clear the item currently selected in the UIChoice. Compile and run the program, select an item in the UIChoice control, then click the "Clear UIChoice" button. This results in the setSelectedIndex method getting called with a value of -1, clearing the previously selected item from the UIChoice control.

Sample Code

   import com.ms.ui.*;
   import com.ms.ui.event.*;

   public class ResetUIChoiceDemo implements IUIActionListener {
     UIChoice choice=null;

     public ResetUIChoiceDemo(UIChoice choice) {
       this.choice=choice;
     }

     public static void main(String args[])
     {
       UIFrame frame = new UIFrame("AFC Frame");
       frame.setSize(320,50);
       frame.setLayout(new UIGridLayout(0,2));
       UIChoice choice=new UIChoice();
       choice.addString("ChoiceA");
       choice.addString("ChoiceB");
       choice.addString("ChoiceC");
       choice.addString("ChoiceD");
       frame.add(choice);
       UIPushButton clearButton=new UIPushButton("Clear UIChoice");
       clearButton.addActionListener(new ResetUIChoiceDemo(choice));
       frame.add(clearButton);
       frame.setVisible(true);
     }

     public void actionPerformed(UIActionEvent e) {
       choice.setSelectedIndex(-1);  // Clear the UIChoice selection.
     }
   }

REFERENCES

For more information please see the Microsoft SDK for Java 2.0x documentation, available at http://www.microsoft.com/java/sdk/.

For the latest Knowledge Base articles and other support information on Visual J++ and the SDK for Java, see the following page on the Microsoft Technical Support site:

   http://support.microsoft.com/support/visualj/
   http://support.microsoft.com/support/java/

Keywords          : AWTPkg
Technology        : kbInetDev internet
Version           : WINDOWS:2.0,2.01
Platform          : WINDOWS
Issue type        : kbhowto


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 27, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.