10 Replies Latest reply on Jun 29, 2009 12:09 PM by oldMster

    Simple DataGrid selection issue...

    rckehoe Level 1

      I have a simple datagrid that is populated by an HTTPService....

       

      I want to return an Alert.show('Please select item from databagrid'); if a user has NOT selected one of the items in the datagrid... Sounds simple, but for some reason cannot figure it out....

       

      Any suggestions ???

        • 1. Re: Simple DataGrid selection issue...
          *Prashant Shelke* Level 4

          Have u checked like that?


          if( dataGrid.selectedIndex < 0) // single selection

          {

                  Alert.show();

          }


          multiselection enabled:


          if( dataGrid.selectedIndices == null ||  dataGrid.selectedIndices.length == 0)

          {

                Alert.show();

          }



          • 2. Re: Simple DataGrid selection issue...
            oldMster Level 3

            When do you want to display the alert? The user has to have time between the HTTP Service populating the data grid, and the time you want to show the alert.  Are they clicking some action button?  In the event you are processing that you want the datagrid to have a selection, then check datagridid.selectedItem == null .  This could be checked on the datagridid.focusOut event as well.

            Mark

            • 3. Re: Simple DataGrid selection issue...
              rckehoe Level 1

              I tried your first method and this is the error that I get:

               

              Cannot access a property or method of a null object reference.

              • 4. Re: Simple DataGrid selection issue...
                oldMster Level 3

                Sounds like you are trying to check it before the datagrid is created.  Where are you trying to do the check?

                • 5. Re: Simple DataGrid selection issue...
                  rckehoe Level 1

                  Maybe... but that sounds impossible... This is how it is setup.

                   

                  I have my datagrid written on the page, I have a button below that says "Delete"... When the delete button is pushed, then it activates some script that checks if an object has been selected, if it has been selected, then it performed a HTTPService to delete the object from the database.

                  • 6. Re: Simple DataGrid selection issue...
                    *Prashant Shelke* Level 4

                    Can you please post your code here?

                    • 7. Re: Simple DataGrid selection issue...
                      rckehoe Level 1

                      Here is the mxml: ++++++++++++++++++

                       

                      <mx:DataGrid y="83" width="630" height="271" horizontalCenter="0"  dataProvider="{ModuleArray}" id="mm"/>

                      <mx:Button y="362" label="Delete" horizontalCenter="-295" click="removeModule();" id="button3"/>

                       

                      Here is the action: ++++++++++++++++++

                       

                      private function removeModule():void {
                             
                              var Title:String = mm.selectedItem.id;
                              var SystemMod:String = mm.selectedItem.system;
                             
                              if(mm.selectedItem == null) Alert.show('You must specify a module above before you can remove it');
                              else{
                                 
                                  if(SystemMod=='true'){
                                      Alert.show('You cannot remove a system module');
                                  }else{
                                     
                                      var RMParams:Object = {username:USERNAME, password:PASSWORD, mod_title:Title};              

                       

                                      var RM:HTTPService = new HTTPService();
                                      RM.method = "POST";
                                      RM.url = URL+"cms/actions/remove_module.php";
                                      RM.addEventListener(ResultEvent.RESULT,removeModuleStatus);
                                      RM.send(RMParams);
                                     
                                  }
                                 
                              }
                             
                          }
                         
                          private function removeModuleStatus(RMevt:ResultEvent):void {
                             
                              var RStatus:String = RMevt.result.root.status;
                              if(RStatus=='true') UpdateModules();
                              else Alert.show("There was an error while attempting to delete the module");
                             
                          }

                      • 8. Re: Simple DataGrid selection issue...
                        oldMster Level 3

                        If you look in the removeModule function, you are accessing the mm.selecteditem.id property, and the  system property, THEN you check to see if it is null.  You need to put the null check in front of the var Title:string.... since they will error with an 'accessing property of a null object' error that you previously reported.  As written, the code will never execute the If(mm.selectedItem == null) code, since if mm.selectedItem is null, it would have already thrown an error.

                        Mark

                        • 9. Re: Simple DataGrid selection issue...
                          rckehoe Level 1

                          Well that was simple.... Thank you.

                          • 10. Re: Simple DataGrid selection issue...
                            oldMster Level 3

                            No problem - simple problems are the only way I get 'points'