【问题标题】:Hide DataGridView gridlines隐藏 DataGridView 网格线
【发布时间】:2013-01-28 06:49:21
【问题描述】:

我已经看到this 的问题,并将CellBorderStyle 设置为None,但由于某种原因,我的DataGridView 上仍有网格线:

这是我用来初始化控件的代码:

public FtpTransferGridView()
{
    this.AutoGenerateColumns = false;
    this.DoubleBuffered = true;
    this.ReadOnly = true;
    this.AllowUserToAddRows = false;
    this.AllowUserToDeleteRows = false;
    this.AllowUserToResizeRows = false;
    this.ShowEditingIcon = false;
    this.RowHeadersVisible = false;
    this.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
    this.AlternatingRowsDefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(240, 240, 225);
    this.RowTemplate.Height = 20;
    this.CellBorderStyle = DataGridViewCellBorderStyle.None;
    this.BackgroundColor = System.Drawing.SystemColors.Window;

    InitializeColumns();
}

我在这里错过了什么?

【问题讨论】:

  • 你试过dataGridView1.AdvancedCellBorderStyle.All = DataGridViewAdvancedCellBorderStyle.None;
  • @V4Vendetta 是的,我做到了,但没有帮助。请参阅我的答案以了解问题所在。

标签: c# winforms datagridview .net-2.0


【解决方案1】:

问题与自定义绘制的进度列单元格有关。

在它的单元格绘制方法中,我的代码类似于:

base.Paint(g, ...);
g.SmoothingMode = SmoothingMode.HighQuality;
if (value <= 0) return;

//paint the progress bar

g.SmoothingMode = SmoothingMode.None;

当方法退出而不绘制进度条时会发生错误,从而使图形平滑模式处于错误状态。

只有在value &lt;= 0检查解决问题后才能设置Graphics的SmoothingMode:

base.Paint(g, ...);
if (value <= 0) return;
g.SmoothingMode = SmoothingMode.HighQuality;

//paint the progress bar

g.SmoothingMode = SmoothingMode.None;

【讨论】:

  • 我想您还应该将相关的绘制逻辑作为问题的一部分发布,因为它没有被推断出来。
  • @V4Vendetta 绘制逻辑与问题无关。问题是当方法完成时SmoothingMode留在HighQuality上,并被系统用于绘制其他单元格及其边界,这显然导致绘制网格线。
猜你喜欢
  • 1970-01-01
  • 2012-06-08
  • 1970-01-01
  • 1970-01-01
  • 2014-04-29
  • 2012-02-18
  • 2015-09-03
  • 1970-01-01
相关资源
最近更新 更多