2016-08-10 4 views
-2

"Hersteller"열의 셀 번호를 가져오고 싶습니다. 그 작업을 수행하는 방법을 알고만한 어떠한 물체C#, for 루프 및 columname

int columnIndex = dataGridView1.CurrentCell.ColumnIndex; 
tring columnName = dataGridView1.Columns[columnIndex].Name; 

for(columnName.Equals("Hersteller") columnIndex++;) { } 

아이디어를 생각하지?

+0

가능한 중복 http://stackoverflow.com/questions/38869341/c-sharp-excellibary-을 get-a-word) – BugFinder

+0

열에는 셀 목록이 있으므로 셀 번호가 없습니다. – HimBromBeere

+1

당신은 이미 이것에 대한 질문이 있습니다. 그리고 위의 코드는 컴파일되지 않습니다 – BugFinder

답변

1

당신은 열을 반복 인덱스 얻을 수 :

int colIndex = -1; 

for (int i = 0; i < dataGridView1.Columns.Count; i++) 
{ 
    if (dataGridView1.Columns[i].Name.Equals("Hersteller")) 
    { 
     colIndex = i; 
     break; 
    } 
} 

if (colIndex > -1) 
    // Found the column, do something 
[C# ExcelLibary 얻을 말씀] (의
+0

잘 작동합니다! 감사! – Gomze