【发布时间】:2016-07-12 19:58:12
【问题描述】:
在 Windows 窗体 DataGridView 中,我试图使所选行具有粗体字体并且不更改背景颜色。
为此,我使用了以下代码:
// This method is used to load the data into the grid
private void GridLoad()
{
// Configures the Data Source
Grid.DefaultCellStyle.SelectionBackColor = Color.Transparent;
Grid.ClearSelection();
}
private void Grid_SelectionChanged(object sender, EventArgs e)
{
var dataGridView = Grid;
foreach (DataGridViewRow row in dataGrid.Rows)
{
row.DefaultCellStyle.Font = dataGrid.Font;
}
if (dataGridView.SelectedRows.Count > 0)
{
var selectedRow = dataGridView.SelectedRows[0];
selectedRow.DefaultCellStyle.Font = new Font(dataGridView.Font, FontStyle.Bold);
}
}
代码有效,当我单击其中一行选择它时,字体变为粗体,但有一个重叠。
文本被重复,原来的常规字体似乎停留在背景上,而新的粗体文本出现在顶部略微向右偏移。
为什么会这样?为什么会发生这种重叠,我该如何解决?
【问题讨论】:
标签: c# .net winforms datagridview