Bonjour,

j'ai un datagrid avec un itemrenderer décrivant une combobox. je souhaiterai à au premier changement de la combobox de la dernière ligne du datagrid ajouter une nouvelle ligne avec une combobox.
J'ai utiliser une solution présente ici:http://www.switchonthecode.com/tutor...-flex-datagrid

Celà fonctionne très bien. Cependant lorsque je vide le arraycollection associé au tableau -en cliquant sur un bouton- et que j'insère des nouvelles lignes, à partir de la deuxième, la combobox garde visible non pas le prompt mais une valeur aléatoire.
Je mets le code en ligne si quelqu'un a une idée:



Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
 
//APPLICATION PRINCIPALE
<?xml version="1.0" encoding="utf-8"?>
<mx:Application 
  xmlns:mx="http://www.adobe.com/2006/mxml" 
  layout="absolute" width="1000" height="600"
  creationComplete="init()" viewSourceURL="srcview/index.html" xmlns:s="library://ns.adobe.com/flex/spark">
  <mx:Script>
    <![CDATA[
		import com.adobe.viewsource.ViewSource;
 
		import mx.collections.ArrayCollection;
		import mx.controls.ComboBox;
		import mx.controls.TextInput;
		import mx.events.DataGridEvent;
		import mx.events.FlexEvent;
		import mx.utils.ObjectProxy;
 
      [Bindable]
      private var tasks:ArrayCollection= new ArrayCollection();
 
      private static const ADD_TASK:String = "Click to Add Task";
 
      private function init():void
      {
      	var srcUrl:String = Application.application.parameters.srcUrl;
        if(srcUrl) {
          ViewSource.addMenuItem(this, srcUrl);
        }
 
 
        tasks.addItem(new Task("0","Images1", "580","940","2010-01-01","2010-02-02", "0;1;1;0;0;1;0","50"));
		tasks.addItem(new Task("0","Videos2", "580","940","2010-01-01","2010-02-02", "0;1;1;0;0;1;0","-1"));
		tasks.addItem(new Task("0","Images0", "580","940","2010-01-01","2010-02-02", "0;1;1;0;0;1;0","0"));
		tasks.addItem(new Task("0","Images3", "580","940","2010-01-01","2010-02-02", "0;1;1;0;0;1;0","0"));
		tasks.addItem(new Task("0","Videos2", "580","940","2010-01-01","2010-02-02", "0;1;1;0;0;1;0","-1"));
        tasks.addItem(new Task("0",ADD_TASK,"", "","","","",""));
      }
 
      private function checkEdit(e:DataGridEvent):void
      {
        // Do not allow editing of Add Task row except for 
        // "Click to Add" column
		 /*if (e.columnIndex==1000){
        	if(e.rowIndex == tasks.length - 1 && e.columnIndex != 0)
          	e.preventDefault();
		 }*/
      }
 
      private function editEnd(e:DataGridEvent):void
      {
		  //	grid.dataProvider
		  if (e.columnIndex==1){  
		  if ( (e.currentTarget.itemEditorInstance.editor!=null) && tasks!=null){
		  var txtIn:ComboBox = 
			  ComboBox(e.currentTarget.itemEditorInstance.editor);
		  var dt:Object = e.itemRenderer.data;
 
		  var count:int=0;
		  var tmpac:ArrayCollection=new ArrayCollection();
		  for each (var tmp:Task in tasks){
			  if (count==e.rowIndex){
			  if (txtIn.text=="Videos2") //contient .png ou .jpg. ....
				  tmp.Time="-1";
			  if ( (txtIn.text!="Videos2") && (tmp.Time=="-1") )
				  tmp.Time="0";
 
			  tmp.Nom=txtIn.text;
			  }
			  tmpac.addItem(tmp);
			  count++;
		  }
 
        // Adding a new task
 
        if(e.rowIndex == tasks.length - 1)
        {
 
          // Add new task
          if(txtIn.text != ADD_TASK)
          {
			  //FAUT ENVOYER DANS LE NOM UN TRUC INCONNU : ADD_TASK N'EXISTE PAS DANS LE TABLEAU DE ITEMRENDERER DONC AFFICHAGE PROMPT
			tmpac.addItemAt(new Task("0",ADD_TASK,"", "","","","",""), e.rowIndex+1);
			tasks=null;
			tasks=new ArrayCollection();
			tasks=tmpac;
			tasks.refresh();
          }
 
 
 
 
        }else{
			tasks=tmpac;
			tasks.refresh();
		}
 
 
 
 
 
 
		  }
 
		  }
 
		  // Destroy item editor
		  grid.destroyItemEditor();
 
		  // Stop default behavior 
		  e.preventDefault();
 
      }
 
		protected function button1_clickHandler(event:MouseEvent):void
		{
			tasks.removeAll();
 
			tasks.addItem(new Task("0",ADD_TASK,"", "","","","",""));
		}
 
		protected function grid_updateCompleteHandler(event:FlexEvent):void
		{
			// TODO Auto-generated method stub
		trace("test");
		}
 
	]]>
  </mx:Script>
 
 
  <mx:DataGrid  
	id="grid" width="100%" height="509" 
    dataProvider="{tasks}" 
    sortableColumns="false" editable="true"
	updateComplete="grid_updateCompleteHandler(event)"
    itemEditBeginning="checkEdit(event)"  
    itemEditEnd="editEnd(event)">
    <mx:columns>
	 	<mx:DataGridColumn headerText="Modif2." editable="false"  dataField="Affectation" />
 
      	<mx:DataGridColumn headerText="Nom" rendererIsEditor="true"  editorDataField="result" itemRenderer="renderer.SizeRenderer"				  
        dataField="Nom" width="250" />
		<mx:DataGridColumn headerText="Modif2." editable="false"  dataField="Nom" />
		<mx:DataGridColumn headerText="H.Deb"  dataField="HDeb" />
		<mx:DataGridColumn headerText="H.Fin"  dataField="HFin" />
		<mx:DataGridColumn headerText="D.Deb"  dataField="DDeb" />
		<mx:DataGridColumn headerText="D.Fin"  dataField="DFin" />
		<mx:DataGridColumn headerText="Days"  dataField="Days" />
		<mx:DataGridColumn headerText="Time"  dataField="Time" />
    </mx:columns>
  </mx:DataGrid>
	<mx:Button x="29" y="520" label="Button" click="button1_clickHandler(event)"/>
</mx:Application>
 
//ITEMRENDERER SizeRenderer
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" horizontalAlign="center">
   <mx:Script>
        <![CDATA[
			import mx.events.ListEvent;
            // Define a property for returning the new value to the cell.
            public var result:String="";
            public var change=false;
            [Bindable]
            private var dpValue:Array = [ 
            	{ label:"Images0", data:"Images0" },
            	{ label:"Images1", data:"Images1"},
            	{ label:"Videos2", data:"Videos2"},
            	{ label:"Images3", data:"Images3"}];
 
 
			// Override the set method for the data property.
			override public function set data(value:Object):void 
			{
				super.data = value;
				if ( (value != null)  )
				{
					var currentValue:String;
					var len:int = dpValue.length;
					currentValue= value.Nom;
 
 
					for (var i:int = 0; i < len; i++) 
					{
						if (dpValue[i].data == currentValue) 
						{
 
							editor.selectedIndex = i;
							break;
						}
					}
					change=true;
				}
 
 
 
			} 
 
			public function onChange(event:ListEvent):void 
			{
				change=true;
				var index:int = editor.selectedIndex;
				result = dpValue[index].data;
 
			}          
 
			protected function editor_changeHandler(event:ListEvent):void
			{
				change=true;
				var index:int = editor.selectedIndex;
				result = event.target.selectedLabel;
			}
 
		]]>
    </mx:Script>
 	<mx:ComboBox id="editor" prompt="Click to Add Task" dataProvider="{dpValue}" width="130" change="onChange(event)"/>
</mx:VBox>