Check for Data Duplicates on a Grid

 Here is a piece of code to prevent duplicate data on a specific field on a page grid. You can of course modify it to check for multiple fields or even the whole row.

/* Check for data duplicates on a grid. */ Local Row &row1, &row2; Local number &r, &r1;
&rs = GetLevel0().GetRow(1).GetRowset(Scroll.grid_table);
For &r = 1 To &rs.ActiveRowCount /*Get grid row*/ &row1 = &rs.GetRow(&r); /*once we have a row, we are going to loop through the grid rows and make sure a specific field value is unique*/ For &r1 = 1 To &rs.ActiveRowCount &row2 = &rs.GetRow(&r1); /* if this is a different row, and the field_name value matches then throw an error*/ If &r1 <> &r And &row1.grid_table.field_name.Value = &row2.grid_table.field_name.Value Then MessageBox(0, "", 0, 0, "Error. Duplicate values are not allowed."); End-If; End-For; End-For; I recommend storing your Error message into the message catalog. If you do that then just replace the last two zeros in the MessageBox Function with your message_set and message_num accordingly.  理解:上面的代码是在level1中把每一行和level1中的所有行做比较(两层For)
posted @ 2013-10-24 12:10  Bryan chen  阅读(298)  评论(0)    收藏  举报