0

I am a new C# user and now I have encountered a problem in using BindingNavigator.

I am using bindingNavigator to update records in a table of database. Before I leave current updated record and enter the next record by clicking Next button, I will perform some validation, if there is any thing incorrect, I hope it could raise a warning to give me chance to correct the wrong fields instead of moving to the next record.

I added some lines in bindingNavigatorMoveNextItem_MouseDown event, but it still move to next item even there are some thing wrong with current record(fields have some logical connection). Can any expert here help me out about that? Many Thanks!

Ria
  • 10,237
  • 3
  • 33
  • 60
Wintop088
  • 3
  • 1
  • 3

2 Answers2

2

You have two approaches: either overriding WndProc and prevent mouse click window message from calling the base's WndProc, or simply overriding OnMouseClick:

class Hello : BindingNavigator
{
    private bool canFire = false;
    protected override void OnMouseClick(MouseEventArgs e) // second approach
    {
        // don't call base method so that event doesn't fire up
        if (this.canFire)
             base.OnMouseClick(e);
    }
}
  • Thanks! I got it and I'd like to rewrite all the navigator buttons, put it differently, I won't use it original buttons and will create them by myself. It will be much easier to me. Thanks! – Wintop088 Jul 19 '12 at 05:31
0

I know this is old.. but for anyone else... You should use the normal buttons, and just use the validating event, canceling if anything fails your validation. The control does not display the property in the designer, but you can still set it : bindingnavigator.CausesValidation = true; I do this in the form load.

this alone still won't do it. you also need to set the focus. bindingnavigator.focus(); I do this in the bindingnavigator_ItemClicked event so it happens no matter what button is clicked.

da Bich
  • 494
  • 1
  • 4
  • 13