我想修改列的网格线的颜色,就是竖着的线的颜色,而且想设置每列之间的线的颜色不一致,我式了一下gridcolor貌似不行..麻烦哪位大虾指导下我,谢谢~

解决方案 »

  1.   

    // Change the Border and Gridline Styles in  the Windows Forms DataGridView ControlSamples:  
     
    this.dataGridView1.GridColor = Color.BlueViolet;  
    this.dataGridView1.BorderStyle = BorderStyle.Fixed3D;  
    this.dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None;  
    this.dataGridView1.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;  
    this.dataGridView1.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single; 
      

  2.   

    只能自己画了,datagridview绘制的时候,是按单元格来绘制的矩形,按你的要求就是绘制矩形的左右边框颜色不同了
    给你一段代码是绘制行头和列头的       protected override void OnCellPainting(System.Windows.Forms.DataGridViewCellPaintingEventArgs e)
           {
               Color mLinearColor1 = Color.FromArgb(248, 250, 251);
               Color mLinearColor2 = Color.FromArgb(196, 207, 224);
               Color mGridColor = Color.FromArgb(120, 147, 191);  //网格线的颜色
               Color mHasFocusedColor = Color.DarkCyan;          //控件的焦点框颜色 
               Rectangle Rect = new Rectangle(e.CellBounds.X - 1, e.CellBounds.Y, e.CellBounds.Width, e.CellBounds.Height - 1);
               LinearGradientBrush LinearGradientBrushs = new LinearGradientBrush(Rect, mLinearColor1, mLinearColor2, LinearGradientMode.Vertical);                     try
               {
                   if (e.RowIndex == -1 || e.ColumnIndex == -1)
                   {
                       e.Graphics.FillRectangle(LinearGradientBrushs, Rect);
                       e.Graphics.DrawRectangle(new Pen(mGridColor), Rect);
                       e.PaintContent(e.CellBounds);
                       e.Handled = true;
                   }
               }           catch
               { }
               finally
               {
                   if (LinearGradientBrushs != null)
                   {
                       LinearGradientBrushs.Dispose();
                   }           }           /*不显示焦点颜色*/
               this.DefaultCellStyle.SelectionBackColor = Color.Transparent ;
               this.DefaultCellStyle.SelectionForeColor  = Color.Black ;
               base.OnCellPainting(e);
           }