![](/img/trans.png)
[英]displaying string of array in datagridview c# windows application
[英]C# - DataGridView ComboBoxCol Displaying Ghost Text of other Cells - Windows Form Application
正如您在下圖中看到的,datagridview 的 combobox col 正在顯示來自較高行的文本的重影圖像。 如果將 cursor 在文本上移動幾次,它就會消失。 上下滾動有時也有幫助。 對導致此問題的原因有任何想法嗎? 謝謝!
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);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.