java中给组合框加监听器,什么事件在DataGridViewCell中的组合框中捕获了值的变化?...

上面的回答让我在报 Spring 花路上走了一段时间 . 它不起作用,因为它导致多个事件触发,只是不断添加事件 . 问题是上面捕获DataGridViewEditingControlShowingEvent并且它没有捕获更改的值 . 因此,每次你聚焦时都会触发,然后离开组合框,无论它是否已经改变 .

关于“CurrentCellDirtyStateChanged”的最后一个答案是正确的方法 . 我希望这可以帮助别人避免陷入兔子洞 .

这是一些代码 .

// Add the events to listen for

dataGridView1.CellValueChanged +=

new DataGridViewCellEventHandler(dataGridView1_CellValueChanged);

dataGridView1.CurrentCellDirtyStateChanged +=

new EventHandler(dataGridView1_CurrentCellDirtyStateChanged);

// This event handler manually raises the CellValueChanged event

// by calling the CommitEdit method.

void dataGridView1_CurrentCellDirtyStateChanged(object sender,

EventArgs e)

{

if (this.dataGridView1.IsCurrentCellDirty)

{

// This fires the cell value changed handler below

dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);

}

}

private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)

{

// My combobox column is the second one so I hard coded a 1, flavor to taste

DataGridViewComboBoxCell cb = (DataGridViewComboBoxCell)dataGridView1.Rows[e.RowIndex].Cells[1];

if (cb.Value != null)

{

// do stuff

dataGridView1.Invalidate();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值