我在使用數據綁定 datagridviewcomboboxcell 時遇到問題我想刪除出現在數據綁定組合框單元格上的藍色選擇線。我注意到如果 comboboxcell 不是數據綁定但有項目集合,則不會出現藍線。但是數據綁定組合框確實有它。項目集合數據綁定你會在第一張圖片中看到沒有藍色選擇線但是在下一張圖片(數據綁定組合框單元格)中有......我需要把這條選擇線拿走,這樣當數據綁定的組合框單元格只有一行數據時,用戶只能通過鍵盤輸入進行選擇。我最初嘗試添加一個 keyDown 事件來設置確實更改了值的 Items[index],但是,當我離開單元格時,它會顯示模型名稱和命名空間。然后,當返回到單元格時,它會顯示該值。我使用以下代碼來執行此操作:我向組合框添加了一個 keydown 事件,這里是 keydown 事件private void dataGridView_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (dataGridView1.Columns[dataGridView1.CurrentCell.ColumnIndex].CellType.Name == "DataGridViewComboBoxCell" && dataGridView1.CurrentCell.ReadOnly == false) { DataGridViewRow row = dataGridView1.CurrentRow; try { if ((row.Cells[dataGridView1.CurrentCell.ColumnIndex] as DataGridViewComboBoxCell).Items.Count == 1) { (dataGridView1.CurrentRow.Cells[dataGridView1.CurrentCell.ColumnIndex] as DataGridViewComboBoxCell).Value = taxcodes[0]; (dataGridView1.CurrentRow.Cells[dataGridView1.CurrentCell.ColumnIndex] as DataGridViewComboBoxCell).DisplayMember = "FullDescription"; (dataGridView1.CurrentRow.Cells[dataGridView1.CurrentCell.ColumnIndex] as DataGridViewComboBoxCell).ValueMember = "TaxID"; } } catch { } } }現在我已經嘗試更改組合框的設置值但沒有運氣,我正在尋找下一個可能的解決方案,我可能會開始工作。如果我可以使 Combobox 在最初選擇時沒有選擇行,那么只要該行移動到列表中的唯一項目,它就會選擇提供選擇該項目作為值的能力。注意:具有多個項目的數據綁定組合框單元格效果很好注意:定義了項目的非數據綁定組合框單元格運行良好,但是我需要一個顯示成員和值成員當組合框只有一項時,此查詢的理想結果將使我能夠選擇數據綁定組合框項(使用 ENTER 鍵)。最后注意:當我使用鼠標在只有 1 個項目的數據綁定組合框單元格上進行選擇時,它工作得很好。感謝您的幫助,如果有人可以提供幫助
有沒有辦法刪除數據網格視圖上數據綁定組合框中的選擇行(突出顯示)?
慕桂英4014372
2022-12-31 12:43:51