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!
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);
}
}