2015-01-02 5 views
0

열의 현재 값을 기반으로 DataGridView의 열 (이미지 삽입, differenet 글꼴로 텍스트 설정 ...)을 사용자 정의하려면 어떻게해야합니까?C# custom datagridview columns

:

열의 값 = 0, I는 단어 "NO"및 열의 값 = 1, I는 단어 "YES"을 표시하고자하는 경우를 표시 할 경우 (또는 I는 CellRenderer을 사용하여 자바)

를 다른 이미지를 넣고, I는 "0"에서 컬럼의 값을 변경하는 경우에 "1"렌더러 자체 "을"NO "에서를 automaticly 워드를 변경할 맡아 예 ".

어떻게 C#에서 동일한 작업을 수행 할 수 있습니까?

+0

사용 Rowdatabound 이벤트 ... – Dhaval

+0

추가 사항 PLS 또는 좋은 링크가, 내가 thnx : C#을 새로운 해요,하고. –

+0

http://www.dotnetgallery.com/kb/resource17-RowDatabound-event-tips-and-tricks-in-Gridview-control.aspx.aspx – Dhaval

답변

0

CellFormatting 이벤트 (msdn)를 사용해야합니다.

예 : 그리드의

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) 
{ 
    if (this.dataGridView1.Columns[e.ColumnIndex].HeaderText == "Value") 
    { 
     if (e.Value != null) 
     { 
      int intValue = (int)e.Value; 
      e.Value = (intValue == 0) ? "NO" : "YES"; 
     } 
    } 
} 
+0

그것은 바로 대답은 내가 datagridview 동적으로 만드는거야, 내가 어떻게 동적으로 만든 datagridview 에이 메서드를 연결할 수 있습니까? –

+0

또는 DataGridView에서 확장되는 클래스를 만들어야합니까? –

+0

이벤트 핸들러를'CellFormatting' 이벤트로 설정해야합니다 :'yourDataGridView.CellFormatting + = dataGridView1_CellFormatting; ' – kmatyaszek