Hi please check out this solution.

The code is bit crude and u will have to generalize it a bit more

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
layout="absolute">
    <mx:AdvancedDataGrid  id="TaskRole1Grid" editable="true"
 allowMultipleSelection="true"
creationComplete="{initGrid()}" x="122" y="61"
color="#09090A" height="50%" width="836">
        <mx:dataProvider>
                <mx:HierarchicalData source="{taskCol}"/>
        </mx:dataProvider>
                    <mx:groupedColumns>
                        <mx:AdvancedDataGridColumn editable="true"
headerText="Task" dataField="task" width="300"/>
                        <mx:AdvancedDataGridColumn
headerText="Assigned To"
dataField="assignedTo" editable="false">
                              <mx:itemRenderer>
                                 <mx:Component>
                                       <mx:ComboBox  tabEnabled="true"
change="data.assignedTo=selectedItem" text="{data.assignedTo}" >
                                            <mx:dataProvider>
                                               <mx:ArrayCollection>

<mx:String>User1</mx:String>

<mx:String>User2</mx:String>

<mx:String>User3</mx:String>

<mx:String>User4</mx:String>
                                                </mx:ArrayCollection>
                                             </mx:dataProvider>
                                       </mx:ComboBox>
                                 </mx:Component>
                              </mx:itemRenderer>
                        </mx:AdvancedDataGridColumn>

                        <mx:AdvancedDataGridColumn
headerText="Priority"
editable="false" dataField="priority">
                              <mx:itemRenderer>
                                 <mx:Component>
                                       <mx:ComboBox  tabEnabled="true"
change="data.priority=selectedItem" text="{data.priority}">
                                            <mx:dataProvider>
                                               <mx:ArrayCollection>

<mx:String>High</mx:String>

<mx:String>Medium</mx:String>

<mx:String>Low</mx:String>

<mx:String>Urgent</mx:String>

<mx:String>None</mx:String>
                                                </mx:ArrayCollection>
                                             </mx:dataProvider>
                                       </mx:ComboBox>
                                 </mx:Component>
                              </mx:itemRenderer>
                        </mx:AdvancedDataGridColumn>
                        <mx:AdvancedDataGridColumn headerText="Status"
editable="false" dataField="status">
                               <mx:itemRenderer>
                                 <mx:Component>
                                       <mx:ComboBox  tabEnabled="true"
change="data.status=selectedItem" text="{data.status}">
                                            <mx:dataProvider>
                                               <mx:ArrayCollection>

<mx:String>Assigned</mx:String>
                                                   <mx:String>Not
Assigned</mx:String>
                                                   <mx:String>Not
Started</mx:String>

                                                </mx:ArrayCollection>
                                             </mx:dataProvider>
                                       </mx:ComboBox>
                                 </mx:Component>
                              </mx:itemRenderer>
                        </mx:AdvancedDataGridColumn>
                    </mx:groupedColumns>
                </mx:AdvancedDataGrid>
        <mx:Button x="172" y="35" label="Add Task" click="addTask()"/>
        <mx:Button x="388" y="35" label="Delete" click="deleteTask()"/
>

    <mx:Script>
    <![CDATA[
        import mx.collections.HierarchicalCollectionView;
        import mx.collections.HierarchicalData;

            import mx.collections.ArrayCollection;

            [Bindable]
            private var taskCol:ArrayCollection = new ArrayCollection
();

            private function initGrid():void
            {
                taskCol = new ArrayCollection();

                //taskCol.addItem({task: "a",assignedTo:
"b",target:"c",priority: "d",status: "e"});
            }

            private function addTask():void
            {

                taskCol.addItem({task: "t1",assignedTo:
"",target:"",priority: "",status: ""});
                                TaskRole1Grid.dataProvider = new 
HierarchicalData(taskCol);
            }

            private function deleteTask():void
            {
                if (taskCol.length > 0 )
                {

                       taskCol.removeItemAt
(TaskRole1Grid.selectedIndex);

                }
            }
         [Bindable]
            private var a1:ArrayCollection = new ArrayCollection
([{task: "t1",assignedTo: "",target:"",priority: "",status: "",
                children:[{task: "t1",assignedTo: "",target:"",priority:
"",status: ""}]

            }])
            private function addSubtask():void
            {
                var dp:HierarchicalCollectionView =
TaskRole1Grid.dataProvider as HierarchicalCollectionView;
                var hd:HierarchicalData = dp.source as HierarchicalData;
                var arr:ArrayCollection = hd.source as ArrayCollection;
                if(arr.length > 0)
                {
                        var o:Object = taskCol.getItemAt(0);
                        var o1:Object = new Array();
                        o1.task = "Subtask";
                        o1.assignedTo = "";
                        o1.target = "";
                        o1.priority = "";
                        o1.status = "";
                        o.children = new Array();
                        o.children.push(o1);
                        arr.removeItemAt(0);
                        arr.addItemAt(o,0);
                        arr.refresh();
                }

                //TaskRole1Grid.dataProvider = new HierarchicalData(arr);

            }
    ]]>
    </mx:Script>

    <mx:Button x="267" y="35" label="Add Sub Task" click="addSubtask
()"/>
</mx:Application>

Thanks and Regards
Nitin

vinod kumar wrote:
> I am using Advanced Datagrid. I am using three buttons. Add Task,AddSubTask,
> Delete Task.I am able to Add and Delete Task. I want to know how is it
> possible to add subtasks like tree structure.That means selecting a Task and
> adding Subtasks for that selected Task. For example, if i have added three
> tasks say Task1,Task2, Task3. If i select Task2 in the datagrid and then
> click the Add Sub Task button. If iam adding 2 subtasks for Task2, it should
> look like this(Like a tree structure)
>
> Task1
> Task2
>         Sub Task1
>         Sub Task2
> Task3
>
>
> Iam attaching the code also.
>
> Please help me
>
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; layout="absolute">
>     <mx:AdvancedDataGrid  id="TaskRole1Grid" editable="true"
> designViewDataType="tree" allowMultipleSelection="true"
> creationComplete="{initGrid()}" dataProvider="{taskCol}" x="122" y="61"
> color="#09090A" height="50%" width="836">
>                     <mx:columns>
>                         <mx:AdvancedDataGridColumn editable="true"
> headerText="Task" dataField="task" width="300"/>
>                         <mx:AdvancedDataGridColumn headerText="Assigned To"
> dataField="assignedTo" editable="false">
>                               <mx:itemRenderer>
>                                  <mx:Component>
>                                        <mx:ComboBox  tabEnabled="true"
> change="data.assignedTo=selectedItem" text="{data.assignedTo}" >
>                                             <mx:dataProvider>
>                                                <mx:ArrayCollection>
>
> <mx:String>User1</mx:String>
>
> <mx:String>User2</mx:String>
>
> <mx:String>User3</mx:String>
>
> <mx:String>User4</mx:String>
>                                                 </mx:ArrayCollection>
>                                              </mx:dataProvider>
>                                        </mx:ComboBox>
>                                  </mx:Component>
>                               </mx:itemRenderer>
>                         </mx:AdvancedDataGridColumn>
>
>
>
>                         <mx:AdvancedDataGridColumn headerText="Priority"
> editable="false" dataField="priority">
>                               <mx:itemRenderer>
>                                  <mx:Component>
>                                        <mx:ComboBox  tabEnabled="true"
> change="data.priority=selectedItem" text="{data.priority}">
>                                             <mx:dataProvider>
>                                                <mx:ArrayCollection>
>
> <mx:String>High</mx:String>
>
> <mx:String>Medium</mx:String>
>
> <mx:String>Low</mx:String>
>
> <mx:String>Urgent</mx:String>
>
> <mx:String>None</mx:String>
>                                                 </mx:ArrayCollection>
>                                              </mx:dataProvider>
>                                        </mx:ComboBox>
>                                  </mx:Component>
>                               </mx:itemRenderer>
>                         </mx:AdvancedDataGridColumn>
>                         <mx:AdvancedDataGridColumn headerText="Status"
> editable="false" dataField="status">
>                                <mx:itemRenderer>
>                                  <mx:Component>
>                                        <mx:ComboBox  tabEnabled="true"
> change="data.status=selectedItem" text="{data.status}">
>                                             <mx:dataProvider>
>                                                <mx:ArrayCollection>
>
> <mx:String>Assigned</mx:String>
>                                                    <mx:String>Not
> Assigned</mx:String>
>                                                    <mx:String>Not
> Started</mx:String>
>
>                                                 </mx:ArrayCollection>
>                                              </mx:dataProvider>
>                                        </mx:ComboBox>
>                                  </mx:Component>
>                               </mx:itemRenderer>
>                         </mx:AdvancedDataGridColumn>
>                     </mx:columns>
>                 </mx:AdvancedDataGrid>
>         <mx:Button x="172" y="35" label="Add Task" click="addTask()"/>
>         <mx:Button x="388" y="35" label="Delete" click="deleteTask()"/>
>
>
>     <mx:Script>
>     <![CDATA[
>
>             import mx.collections.ArrayCollection;
>
>
>             [Bindable]
>             private var taskCol:ArrayCollection;
>
>             private function initGrid():void
>             {
>                 taskCol = new ArrayCollection();
>                 //taskCol.addItem({task: "a",assignedTo: "b",target:
> "c",priority: "d",status: "e"});
>             }
>
>             private function addTask():void
>             {
>
>                 taskCol.addItem({task: "",assignedTo: "",target:
> "",priority: "",status: ""});
>
>             }
>
>             private function deleteTask():void
>             {
>                 if (taskCol.length > 0 )
>                 {
>
>                         taskCol.removeItemAt(TaskRole1Grid.selectedIndex);
>
>
>                 }
>             }
>     ]]>
>     </mx:Script>
> <mx:Binding source="TaskRole1Grid.dataProvider as ArrayCollection"
> destination="taskCol" />
>     <mx:Button x="267" y="35" label="Add Sub Task"/>
> </mx:Application>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Flex 
India Community" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/flex_india?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to