'C# - DataGridView ComboBoxCol Displaying Ghost Text of other Cells - Windows Form Application
As you can see in the image below the combobox col of the datagridview is displaying ghost images of text from higher rows. If you move the cursor over the text several times it goes away. Scrolling up and down sometimes helps as well. Any thoughts on what is causing this issue? Thanks!
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";
Solution 1:[1]
Changing the displayStyle from DropDown to ComboBox resolves the issue. I don't like the look as much however it is fully functional this way.
If someone else has a better response please chime in. Thanks!
Solution 2:[2]
I hooked into the CellPainting event handler. Not sure why, but each time you paint the cell, the ghosting fades a little more. 3 times seems to do the trick:
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);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Steven Marcus |
Solution 2 | PaladinMattt |