2010-12-07 8 views
1

Windows Forms에서 DataGrid (gridview 또는 datagridview가 아님)가 있습니다. Microsoft Visual Studio 2003에서 작성되었습니다. 2008로 변환되었습니다. 조건에 따라 DataGrid의 datarow를 변경해야합니다.어떻게 프로그래밍 방식으로 데이터 격자 행의 배경색을 설정합니까

내가 봤 발견 한 같은

과 같은 몇 가지 예

내가 어떤 "DataGridRowEventArgs"인수가없는

그러나 무효 myDataGrid_LoadingRow (개체를 보낸 사람, DataGridRowEventArgs 전자).

또한 나는 그들이 하나의 특정 셀의 색상을 변경

http://www.syncfusion.com/faq/windowsforms/faq_c44c.aspx, 하나를 발견했다.

그러나 일부 조건에 따라 Windows Form의 Datagrid에서 전체 행의 색을 어떻게 변경합니까?

미리 감사드립니다.

감사 힌트로

SKR

답변

0

사용이 :

private void dataGridView1_CellFormatting(object sender,   DataGridViewCellFormattingEventArgs e) 
{ 
    foreach (DataGridViewRow Myrow in dataGridView1.Rows) 
    {   //Here 2 cell is target value and 1 cell is Volume 
     if (Convert.ToInt32(Myrow .Cells[2].Value)<Convert.ToInt32(Myrow .Cells[1].Value))// Or your condition 
     { 
      Myrow .DefaultCellStyle.BackColor = Color.Red; 
     } 
     else 
     { 
      Myrow .DefaultCellStyle.BackColor = Color.Green; 
     } 
    } 
관련 문제