EasyCFM.COM ColdFusion Forums / Flex Development / preselecting the first row in a flex datagrid

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: preselecting the first row in a flex datagrid -- page: 1 2 3 4

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

kicker
03-15-2008 @ 10:41 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 717
Joined: Oct 2004

Take the function that you have for the change event, edit it so it can get called right after your code for selecting the index. So that your index is selected in your grid before you try to call the grid.selectedIndex/grid.selectedItem info.

Craig

stinasius
03-15-2008 @ 11:10 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 109
Joined: Jan 2007

hi, am not sure what you mean. but this is my function for the change event,
private function selectedItemChanged(evt:Event):void{
                    parentDocument.next_meeting.text = meetings_dg.selectedItem.next_meeting;
                    parentDocument.topic.text = meetings_dg.selectedItem.topic;
                    parentDocument.speaker.text = meetings_dg.selectedItem.speaker;
                    parentDocument.about_presentation.text = meetings_dg.selectedItem.about_presentation;
                    parentDocument.about_speaker.text = meetings_dg.selectedItem.about_speaker;
               }

stinasius
03-15-2008 @ 11:12 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 109
Joined: Jan 2007

how can i  edit it so it can get called right after my code for selecting the index

kicker
03-15-2008 @ 12:00 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 717
Joined: Oct 2004

You are probably not going to like this answer, but you need to actually learn this. All code that I have ever written be it cf, as, java, etc things happen in order. How do you make var a be called after var b?

Craig

stinasius
03-17-2008 @ 7:54 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 109
Joined: Jan 2007

please kicker i understand what you are trying to say, but am still new to flex and AS. an example will be of great help.thanks

kicker
03-17-2008 @ 10:56 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 717
Joined: Oct 2004

Ok here is the answer which you had all along.

< ?xml version="1.0" encoding="utf-8"?>
< mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
     < mx:Script>
          <![CDATA[
               [Bindable]
               private var dp:Array = [{user: "Admin", pass: "admin"},{user: "John", pass: "doe"},{user: "Jane", pass: "doe"},{user: "Webmaster", pass: "web"}];
          
               private function init():void
               {
                    //call the selected index first
                    dg.selectedIndex = 0;
                    //now
that something is selected lets display it.
                    sendToTextInputs();
               }
               //shown on startup
               private function sendToTextInputs():void
               {
                    name_txt.text = dg.selectedItem.user;
                    pass_txt.text
= dg.selectedItem.pass;
               }
               //Shown
after a user clicks on something in the grid
               private function showChangeValues(evt:Event):void
               {
                    name_txt.text = dg.selectedItem.user;
                    pass_txt.text
= dg.selectedItem.pass;
               }     
          ]]>

     </ mx:Script>
     < mx:DataGrid x="10" y="10" id="dg" dataProvider="{dp}" change="showChangeValues(event)">
          < mx:columns>
               < mx:DataGridColumn headerText="Username" dataField="user"/>
               < mx:DataGridColumn headerText="Password" dataField="pass"/>
          </ mx:columns>
     </ mx:DataGrid>
     < mx:TextInput x="10" y="184" id="name_txt"/>
     < mx:TextInput x="10" y="214" id="pass_txt"/>

</  mx:Application>


good luck. Smile

Craig

This message was edited by kicker on 3-17-08 @ 10:58 AM

stinasius
03-18-2008 @ 2:22 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 109
Joined: Jan 2007

Hi am now getting this error;
TypeError: Error #1009: Cannot access a property or method of a null object reference.
     at components::meeting_dg/populateTextInputs()
     at components::meeting_dg/initMeeting()
     at components::meeting_dg/___HBox1_creationComplete()
     at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
     at flash.events::EventDispatcher/dispatchEvent()
     at mx.core::UIComponent/dispatchEvent()
     at mx.core::UIComponent/set initialized()
     at mx.managers::LayoutManager/::doPhasedInstantiation()
     at Function/http://adobe.com/AS3/2006/builtin::apply()
     at mx.core::UIComponent/::callLaterDispatcher2()
     at mx.core::UIComponent/::callLaterDispatcher()


here is my code.

private function init():void
               {
                    //call the selected index first
                         meetings_dg.selectedIndex = 0;
                    //now that something is selected lets display it.
                    populateTextInputs();
               }
            
            public function populateTextInputs():void
               {
                     parentDocument.next_meeting.text = meetings_dg.selectedItem.next_meeting;
                         parentDocument.topic.text = meetings_dg.selectedItem.topic;
                         parentDocument.speaker.text = meetings_dg.selectedItem.speaker;
                         parentDocument.about_presentation.text = meetings_dg.selectedItem.about_presentation;
                         parentDocument.about_speaker.text = meetings_dg.selectedItem.about_speaker;
               }                                  
            
               public function selectedItemChanged(evt:Event):void{
                    parentDocument.next_meeting.text = meetings_dg.selectedItem.next_meeting;
                    parentDocument.topic.text = meetings_dg.selectedItem.topic;
                    parentDocument.speaker.text = meetings_dg.selectedItem.speaker;
                    parentDocument.about_presentation.text = meetings_dg.selectedItem.about_presentation;
                    parentDocument.about_speaker.text = meetings_dg.selectedItem.about_speaker;
               }

kicker
03-18-2008 @ 7:24 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 717
Joined: Oct 2004

How are you getting the information into the datagrid? Is it a query from a cfc? Some data comes back to a Flex app with all capital letters. Since Actionscript is case sensitive if your dqatagrid dataField attributes are capitalized you will need to make your datagrid.selectedItem.DATAFIELD caps as well. If you can see the information in your datafield make the selectedItems statements match exactly as it.

Also you may want to remove the parentDoc parameter from your textinput fields. Unless you are coding in classes and working in multi depths it is unnecessary. And if you don't understand the above the chances are you are working with one depth and don't need it. Not necessarily best practice, but a lot less coding to type.  Wink

Oh, btw. Anytime you receive that message/error it is because a variable is empty. Sort of like a cfparam with no default specified. But unlike cf actionscript does not like empty values in most cases. (Not unless you code for them.)



Craig

stinasius
03-18-2008 @ 8:04 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 109
Joined: Jan 2007

information is getting into the datagrid through a cfc query, and the datagrid datafield attributes are not capitalized, they are all small letters eg topic, speaker etc. i use parentDoc because the datagrid is a component that is loaded into another mxml component that houses the textinputs. so am still stuck.
here is my cfc that loads data into the datagrid.

<cffunction name="getMeetings" output="false" access="remote" returntype="query">
     <cfargument name="id" required="true" type="numeric" default="0">
     <!---<cfset var discussions= "">--->
     <cfset var result= "">          
          <cfquery name="meetings" datasource="usr_grp">
               SELECT          *
               FROM             meeting     
            ORDER BY next_meeting                                                  
          </cfquery>
          <cfquery dbtype="query" name="results">
          select *
          FROM meetings          
          </cfquery>
          <cfreturn results>
     </cffunction>


This message was edited by stinasius on 3-18-08 @ 8:08 AM

stinasius
03-18-2008 @ 8:12 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 109
Joined: Jan 2007

sorry i dont know why its not showing the full code.

PAGE: 1 2 3 4

Website Designed and Developed by Pablo Varando.