5/26/2010 3:41:43 AM
Title:
datagrid duplicates
Hi,
I have two datagrids and one button, Whenever I click button the popupdatagrid comes, then i willl add three rows(10 record, 11th record, 12th record), Again i am clicking add
button and i add 12th record, it will be adding but i dont want to add , it will gives an alert.
How to do it, Please help me
Thanks in advance
Ramakrishna
5/26/2010 4:40:04 AM
if you want to restrict the records upto 11th. Then you can put the condition before adding the code which checks the length of dataProvider and shows alert instead of adding the record.i.e
if(dataProvider.length<11){
//here goes your code which adds record to data grid
}else{
alert.show("You are not allowed to add the 12th record.")
}
5/26/2010 8:43:57 PM
hi,
I am asking about duplicate records. not length?
Thanks in advance
Rama
5/26/2010 10:54:09 PM
write a loop to check if the record exists in the datagrid if not then add it. You need to check for some unique variable that exists in your records. Like your record is
Type Value
---------------
Fruits Apple
Fruits Banana
Fruits Orange
You should check for "Value" here
// replace this code by code where you are adding the new record on button click
var newRecordUniqueVariable= Record.value;
var recordFound:Boolean=false:
for(var i:int;i<dataprovider.length;i++){
if(dataprovider[i].value == Record.value){
recordFound=true;
}
}
if(recordFound==true{
//show alert record cannot be added
}else{
//add the record
}
}