开发者

Winforms Databound ComboBox doesn't update when close Window

I have a combobox that is databound and updates with no issues. The problem I have is if the user types something into the combobox and then uses the [X] close button in the window without tabbing out, the data is not updated. I've been looking all over the web, but can't find any relevant help/tips. The only idea is have is to force an out of focus and m开发者_如何转开发aybe that would force the combobox to see the update.


Try adding the FormClosing event on your form.

The FormClosing event occurs as the form is being closed.

private void Form1_FormClosing(Object sender, FormClosingEventArgs e) 
{    
  //force an event to have the cbo updates fire.
  txtFoo.Focus();
}

or VB.NET

Private Sub Form1_FormClosing(sender as Object, e as FormClosingEventArgs) _ 
     Handles Form1.FormClosing

    'force an event to have the cbo updates fire.
     txtFoo.Focus()
End Sub

From there, you can call the method/logic to have your combobox's contents saved to your datastore.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜