2013-10-02 28 views

回答

0
foreach (DataGridViewRow row in dataGridView1.SelectedRows) 
{ 
    row.DefaultCellStyle.BackColor = Color.Blue; 
} 
+0

我使用的DevExpress GridView的 – Vaseph

+0

哎呀。你没有提到。 :) – Muctadir

0

试试这个,

To change selected rows

private void button1_Click(object sender, EventArgs e) 
    { 
     foreach (DataGridViewRow item in dataGridView1.SelectedRows) 
     { 
      if (null != item) 
      { 
       item.DefaultCellStyle.BackColor = Color.Blue; 
      } 
     }    
    } 

To change all rows

foreach (DataGridViewRow item in dataGridView1.Rows) 
{ 
} 
3

我相信你在说的是DevExpress XtraGrid。如果是这样,那么有多种方法可以突出显示DevExpress XtraGrid中的特定行,具体取决于您的任务。 例如,要突出显示任何选择的行你可以使用下面的代码:

gridView1.Appearance.SelectedRow.BackColor = Color.Red; 

为了强调通过使用自定义条件的特定行,你可以使用GridView.RowStyle事件:

void gridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e) { 
    if((e.State & DevExpress.XtraGrid.Views.Base.GridRowCellState.Selected) != 0) { 
     // check some conditions 
     e.HighPriority = true; 
     e.Appearance.BackColor = Color.Blue; 
    } 
} 

请阅读更多以下帮助文章中的所有这些方法:Customizing Appearances of Individual Rows and Cells

0

对于gridview,请为事件CellFormatting设置以下方法

private void StocksDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { 
    StocksDataGridView.Rows[e.RowIndex].DefaultCellStyle.BackColor = System.Drawing.Color.OrangeRed; 
} 
0

你说你用过DevexpressGrid。因此可以通过在设计时更改girdView's properties来轻松实现。

enter image description here