Easy way to prevent a user from unchecking a checkbox in a datagrid

Hi i have a checkbox datagridcolumn inside a datagrid, how can i prevent user from unchecking the checkbox located in first row without creating a whole itemrenderer etc..

//someArray is bindable

<mx:DataGrid  id="somegrid" dataProvider="{someArray}" >
  <mx:columns>
    ....etc...
        <mx:DataGridColumn dataField="isChecked" rendererIsEditor="true" editorDataField="selected" >
               <mx:itemRenderer>
	<fx:Component>
	      <mx:CheckBox   click="outerDocument.displayCheckBox_clickHandler()" />  
                   </fx:Component>
               </mx:itemRenderer>
        </mx:DataGridColumn>	
</mx:columns>
</mx:DataGrid>

public function displayCheckBox_clickHandler():void
{
        if(somegrid.selectedIndex==0)
       {
              // set the filterArray[0].isChecked = true
              // basically check the checkbox again, but this does NOT work, the filterArray[0].isChecked is set to false again.
             // i think due to the way the events are ran.  
             //This is my question, how do you prevent a user from unchecking the checkbox in first row of the datagrid
            //OR  to auto recheck it after they uncheck it.        
      }
}

Open in new window

LVL 1
gagaliyaAsked:
Who is Participating?
 
dgofmanCommented:
I cannnot understand an answer from xuserx2000

So, my solution is

<fx:Script>
	<![CDATA[
		[Bindable]
		private var someArray:Array = [{isChecked:1},{isChecked:2},{isChecked:3}];
	]]>
</fx:Script>
<mx:DataGrid  id="somegrid" dataProvider="{someArray}" >
	<mx:columns>
		<mx:DataGridColumn dataField="isChecked">
			<mx:itemRenderer>
				<fx:Component>
					<mx:CheckBox>
						<fx:Script>
							<![CDATA[
								override public function get selected():Boolean{
									return (listData && listData.rowIndex == 0 ? true : super.selected);
								}
							]]>
						</fx:Script>
					</mx:CheckBox>  
				</fx:Component>
			</mx:itemRenderer>
		</mx:DataGridColumn>	
	</mx:columns>
</mx:DataGrid>

Open in new window

0
 
Ron MalmsteadInformation Services ManagerCommented:
Checkbox1.enabled = false

It will still be visible...but clicking on it will do nothing.
0
 
gagaliyaAuthor Commented:
Thanks that's exactly what I was looking for.

Not quite sure what xuserx2000 was talking about either.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.