请问在Winform的Datagridview的单元格中,如何时间单单元格显示多种颜色?
比如一个100长的单元格 前10是红色,后10是绿色,再后面又是红色这样的效果?

解决方案 »

  1.   

    百度: datagridview 的 CellPainting 事件
      

  2.   

    private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e) 

    if (e.RowIndex >= dataGridView1.Rows.Count - 1) 
    return; 
    DataGridViewRow dgr = dataGridView1.Rows[e.RowIndex]; 
    try 

    if (dgr.Cells["列名"].Value.ToString() == "比较值") 

    dgr.DefaultCellStyle.ForeColor = 设置的颜色; (如:Color.red)


    catch (Exception ex) 

    MessageBox.Show(ex.Message); 

      

  3.   


    谢谢,使用这个事件已经尝试成功 在一个grid中显示多个色条。