9 Replies Latest reply on Aug 19, 2011 11:08 AM by Brad.White

    problem desecting items in spark list?

    barnetj1 Level 1

      Hi All,

      Ok i have a spark list and allowMultipleSelects is equal to true.. All i want to do is deselect all the items that user has selected when he/she hits a button.. But this does not happen.. I have tried..

       

      list.selectedIndex = -1;
      list.selectedIndices = new <int>[-1];

       

      nothing works, all the values stay the same, as when they were first selected..

       

      Thanks

        • 1. Re: problem desecting items in spark list?
          barnetj1 Level 1

          Anyone know the answer to this? Is it bug in the spark List component?

          • 2. Re: problem desecting items in spark list?
            UbuntuPenguin Level 4

            Have you tried something like this

             

            list.selectedItems = null;

                         or

            list.selectedIndices = null;

             

            It may not like the null value , so you may have to make an empty vector and set the selectedItems/selectedIndices to that.  I don't know how it would look exactly since I haven't used a Vector in Flex 4 , but I'm sure there is some literature around.

             

            If this post was helpful , please mark it as such.

             

            Sincerely ,

              Ubu

            • 3. Re: problem desecting items in spark list?
              barnetj1 Level 1

              Pen thanks..

              I have tried this..

              list.selectedIndices = new [-1];

               

              does not work..

               

              and these do not work either..

              list.selectedIndices = null;

              list.selectedIndex = null;

               

              Thanks

              • 4. Re: problem desecting items in spark list?
                barnetj1 Level 1

                Sorry this

                list.selectedIndices = new [-1];

                 

                should be..

                 

                list.selectedIndices = new <int>[-1];

                 

                thanks

                • 5. Re: problem desecting items in spark list?
                  barnetj1 Level 1

                  I also have tried this..

                  list.selectedIndices = new <int>[];

                   

                  and nothing.. the first selected values, are still selected in the spark list on the second time through

                  • 6. Re: problem desecting items in spark list?
                    Peter deHaan Level 4

                    @barnetj1,

                     

                    Can you please file a Spark List bug at http://bugs.adobe.com/flex/ against the Flex SDK (and include a simple test case) and somebody from Adobe can take a closer look.

                     

                    Thanks,

                    Peter

                    • 7. Re: problem desecting items in spark list?
                      Peter deHaan Level 4

                      Actually, I'm unable to reproduce the issue with this simplified test case:

                       

                      <?xml version="1.0" encoding="utf-8"?>
                      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                                     xmlns:s="library://ns.adobe.com/flex/spark">
                      
                          <fx:Script>
                              <![CDATA[
                                  import mx.utils.ObjectUtil;
                      
                                  protected function btn_clickHandler(evt:MouseEvent):void {
                                      lst.selectedIndices = new Vector.<int>();
                                      callLater(btn_creationCompleteHandler, [evt]);
                                  }
                      
                                  protected function btn_creationCompleteHandler(evt:Event):void {
                                      debbie.text = ObjectUtil.toString(lst.selectedIndices);
                                  }
                              ]]>
                          </fx:Script>
                      
                          <s:controlBarContent>
                              <s:Button id="btn"
                                        label="clear selected indices"
                                        creationComplete="btn_creationCompleteHandler(event);"
                                        click="btn_clickHandler(event);" />
                      
                              <s:Label id="sdkVer" initialize="sdkVer.text = mx_internal::VERSION;" />
                              <s:Label text="{Capabilities.version}" fontWeight="bold" />
                          </s:controlBarContent>
                          <s:layout>
                              <s:VerticalLayout paddingLeft="20" paddingRight="20" paddingTop="20" paddingBottom="20" />
                          </s:layout>
                      
                          <s:List id="lst" labelField="fontName" allowMultipleSelection="true" width="200" change="btn_creationCompleteHandler(event);">
                              <s:layout>
                                  <s:VerticalLayout requestedRowCount="10" gap="0" horizontalAlign="contentJustify" />
                              </s:layout>
                              <s:dataProvider>
                                  <s:ArrayList source="{Font.enumerateFonts(true)}" />
                              </s:dataProvider>
                          </s:List>
                      
                          <s:TextArea id="debbie" />
                      
                      </s:Application>
                      
                      
                      
                      Peter

                      • 8. Re: problem desecting items in spark list?
                        MichaelDelaney Level 1

                        Try validating the display list after setting the selected index, this will force the list to refresh.

                        list.selectedIndex = -1;
                        list.validateDisplayList();

                        Worked for me ^_^

                        • 9. Re: problem desecting items in spark list?
                          Brad.White Level 1

                          I finally got it working with this:

                           

                          list.selectedItems = null;

                          list.validateProperties();

                           

                          Good luck.