![](/img/trans.png)
[英]How to run Run CellEndEdit only when Cell ValueChanged in DataGridView
[英]How to Trigger DataGridView CellEndEdit When A Cell Value Changes Programmatically
我有一個 datagridview,它更新 CellEndEdit 方法上的數據庫。 當用戶按 F10 時,在股票代碼列的單元格上會打開一個新列表,用戶可以選擇一個新代碼。 我的 datagridview 單元格的值會更新,但 CellEndEdit 不會觸發。 我以前曾嘗試過在用戶在這些單元格上按 F10 時處理 CellEndEdit 但它失敗了(我相信我的論點等是非常錯誤的)。 我已經看過以編程方式處理事件,但它沒有用。 我想知道如何在 KeyDown 方法中觸發 CellEndEdit。
private void dataGridView2_KeyDown_1(object sender, KeyEventArgs e)
{//F10 A BASILDIĞINDA EGER STOK KODU HUCRELERİNDEN BASILDIYSA STOK KODLARI AÇILIYOR
if (e.KeyCode == Keys.F10)
{
int satir = dataGridView2.CurrentCell.RowIndex;
int sutun = dataGridView2.CurrentCell.ColumnIndex;
if (sutun == 7)
{
// dataGridView2[e.ColumnIndex, e.RowIndex] = STOKKODU0COMBOBOX;
using (StokKoduListeForm stokkodulisteform = new StokKoduListeForm(secilenveritabani))
{
stokkodulisteform.ShowDialog();
dataGridView2[sutun, satir].Value = (stokkodulisteform.stokkodugetir());
}
}}
我試過了
DataGridViewCellEventArgs a = new DataGridViewCellEventArgs(sutun, satir);
dataGridView2_CellEndEdit_1(dataGridView2, a);
在 using 內部,但它以某種方式顯示了來自另一種形式的消息框。
更改單元格值不會觸發 EndEdit 事件。 調用 BeginEdit 然后調用 EndEdit 可能會觸發 EndEdit 事件。 請更改如下代碼並嘗試。
using (StokKoduListeForm stokkodulisteform = new StokKoduListeForm(secilenveritabani))
{
dataGridView2.BeginEdit(true);
stokkodulisteform.ShowDialog();
dataGridView2[sutun, satir].Value = (stokkodulisteform.stokkodugetir());
dataGridView2.EndEdit();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.