C# - DataGridView ComboBoxCol 显示其他单元格的幻影文本 - Windows 表单应用程序
C# - DataGridView ComboBoxCol Displaying Ghost Text of other Cells - Windows Form Application
正如您在下图中看到的,datagridview 的组合框 col 正在显示较高行的文本重影图像。如果将光标多次移动到文本上,它就会消失。上下滚动有时也有帮助。对导致此问题的原因有任何想法吗?谢谢!
mainDataGridView.DataSource = bindingSourceDataGridView;
mainDataGridView.AutoGenerateColumns = false;
DataGridViewComboBoxColumn ColComboBox = new DataGridViewComboBoxColumn();
mainDataGridView.Columns.Add(ColComboBox);
ColComboBox.HeaderText = "Category";
ColComboBox.ValueType = typeof(string);
ColComboBox.DisplayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton;
//ColComboBox.DisplayIndex = 0;
ColComboBox.Width = 175;
ColComboBox.DataSource = clSQLServer.getTransactionCategory();
ColComboBox.DisplayMember = "transactionCategory";
ColComboBox.ValueMember = "transactionCategoryID";
ColComboBox.Name = "transactionCategory"; //Category
ColComboBox.DataPropertyName = "transactionCategoryID"; //CategoryID
DataGridViewTextBoxColumn textBoxColumn = new DataGridViewTextBoxColumn();
mainDataGridView.Columns.Add(textBoxColumn);
textBoxColumn.HeaderText = "Memo";
textBoxColumn.DataPropertyName = "Memo";
将 displayStyle 从 DropDown 更改为 ComboBox 解决了这个问题。我不太喜欢它的外观,但它以这种方式完全可用。
如果其他人有更好的回复,请补充。谢谢!
我连接到 CellPainting 事件处理程序。不知道为什么,但每次绘制单元格时,重影都会消退一点。 3 次似乎可以解决问题:
private void dataGridView1_CellPainting(object sender,
DataGridViewCellPaintingEventArgs e)
{
if(e.RowIndex >= 0 && e.ColumnIndex == col_jobtitle.Index)
{
//Due to a Windows 11 ghosting bug in in the
// combobox cell, if we repaint it 3 times,
// the ghosting goes away...
e.Paint(e.ClipBounds, e.PaintParts);
e.Paint(e.ClipBounds, e.PaintParts);
e.Paint(e.ClipBounds, e.PaintParts);
}
}
正如您在下图中看到的,datagridview 的组合框 col 正在显示较高行的文本重影图像。如果将光标多次移动到文本上,它就会消失。上下滚动有时也有帮助。对导致此问题的原因有任何想法吗?谢谢!
mainDataGridView.DataSource = bindingSourceDataGridView;
mainDataGridView.AutoGenerateColumns = false;
DataGridViewComboBoxColumn ColComboBox = new DataGridViewComboBoxColumn();
mainDataGridView.Columns.Add(ColComboBox);
ColComboBox.HeaderText = "Category";
ColComboBox.ValueType = typeof(string);
ColComboBox.DisplayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton;
//ColComboBox.DisplayIndex = 0;
ColComboBox.Width = 175;
ColComboBox.DataSource = clSQLServer.getTransactionCategory();
ColComboBox.DisplayMember = "transactionCategory";
ColComboBox.ValueMember = "transactionCategoryID";
ColComboBox.Name = "transactionCategory"; //Category
ColComboBox.DataPropertyName = "transactionCategoryID"; //CategoryID
DataGridViewTextBoxColumn textBoxColumn = new DataGridViewTextBoxColumn();
mainDataGridView.Columns.Add(textBoxColumn);
textBoxColumn.HeaderText = "Memo";
textBoxColumn.DataPropertyName = "Memo";
将 displayStyle 从 DropDown 更改为 ComboBox 解决了这个问题。我不太喜欢它的外观,但它以这种方式完全可用。
如果其他人有更好的回复,请补充。谢谢!
我连接到 CellPainting 事件处理程序。不知道为什么,但每次绘制单元格时,重影都会消退一点。 3 次似乎可以解决问题:
private void dataGridView1_CellPainting(object sender,
DataGridViewCellPaintingEventArgs e)
{
if(e.RowIndex >= 0 && e.ColumnIndex == col_jobtitle.Index)
{
//Due to a Windows 11 ghosting bug in in the
// combobox cell, if we repaint it 3 times,
// the ghosting goes away...
e.Paint(e.ClipBounds, e.PaintParts);
e.Paint(e.ClipBounds, e.PaintParts);
e.Paint(e.ClipBounds, e.PaintParts);
}
}