2014-09-08 3 views
0

gridview에서 다른 행의 두 셀에 같은 값이 있는지 찾아야합니다. 이 코드를 사용했지만 수백만 건의 레코드를 작성하는 데는 많은 시간이 걸립니다. 최적의 방법을 말해 줄 수 있어요?Gridview-Optimimal Way에서 중복 열 값 찾기?

사람은 문을위한 'otherRow'에 grv.Rows.Count에 -1 실종있어 나에게 최적의 방법

+1

당신은'Cells'의 정수 인덱스가 필요합니다, 나는 여기 영업 이익은 같은 문제에 http를 파악하는 방법에 비슷한 질문 모양은 당신이 열 이름 – Habib

+0

에 따라 셀을 참조 할 수 있다고 생각합니다. com/questions/15813266/compare-two-cells-on-same-row-in-datagrid – MethodMan

+0

@Habib 매우 감사드립니다. 수백만 행이 있다면이 방법은 시간이 오래 걸립니다. 어떤 접근 방식을 취해야한다고 말할 수 있습니까? –

답변

0

를 제안 할 수 있습니다. // 유래 :

public void HighlightDuplicate(GridView grv) 
{ 
    //use the currentRow to compare against 
    for (int currentRow = 0; currentRow < grv.Rows.Count - 1; currentRow++) 
    { 
     GridViewRow rowToCompare = grv.Rows[currentRow]; 
     //specify otherRow as currentRow + 1 
     //This forloop loops over more rows then exist 
     for (int otherRow = currentRow + 1; otherRow < grv.Rows.Count -1; otherRow++) 
     { 
      GridViewRow row = grv.Rows[otherRow]; 

      bool duplicateRow = true; 
      //compare cell ENVA_APP_ID between the two rows 
      if (!rowToCompare.Cells["ENVA_APP_ID"].Text.Equals(row.Cells["ENVA_APP_ID"].Text)) 
      { 
       duplicateRow = false; 
       break; 
      } 
      //highlight both the currentRow and otherRow if ENVA_APP_ID matches 
      if (duplicateRow) 
      { 
       rowToCompare.BackColor = System.Drawing.Color.Red;      
      } 
     } 
    } 
}