2013-05-09 4 views
0

현재 DataGridView에 프로그래밍 방식으로 데이터를 추가하려고하지만 작동하지 않는 것 같습니다. 내가 가지고있는 것은 내가 텍스트 파일에서 입력 배열입니다 :DataGridView : 특정 셀에 프로그래밍 방식으로 데이터 추가

public static string PathList = @"C:\Users\gbbb\Desktop\Pfade.txt"; 
_PathRows = System.IO.File.ReadAllLines(@PathList); 

나는 내가 경로를 가지고 내가 많은 행을 추가하는 4 열,있는 DataGridView에 있습니다

public void InitPathsTable() 
{ 
TabelleBib.Rows.Add(_PathRows.Length); 
//And here is where i want to add the Paths on Column Nr.4 
} 

다음은 내가 얻은 모든 경로를 열 Nr.4에 추가하는 방법입니다 ( 행 당 하나의 경로). 하지만 나 같은 초보자에게는 거의 불가능한 것처럼 보입니다. 그래서 나는 당신에게 묻습니다.

+0

어떻게 추가하려고 다시 올 것이다 : (특히 당신이 당신에게 DataGridView 4 열을 추가해야합니다) 댓글 읽기 데이터를 4 번째 열로? 무엇을 얻었습니까 (오류)? – Fabio

답변

0

이렇게하는 방법입니다. 당신은 더 이상 문제를 얻는 경우에

public void InitPathsTable() 
{ 
     int rowindex; 
     DataGridViewRow row; 

     foreach (var line in _PathRows) 
     { 
       rowindex = TabelleBib.Rows.Add(); //retrieve row index of newly added row 
       row = TabelleBib.Rows[rowindex]; //reference to new row 

       row.Cells[3].Value = line; //set value of 4th column to line. WARNING: TabelleBib has to have 4 columns added either from code or designer othwerwise here you will get exception 
     } 
} 

가 댓글을 작성하고 난 당신 :

관련 문제