Board index » cppbuilder » Disable Default Actions: Navigator

Disable Default Actions: Navigator


  Using DBNavigator. I want to disable nbfirst, nbLast, nbPrior, nbLast,
nbDelete and nbRefresh default action when I have a flag set to indicate
I am in edit or insert mode. I really would like to have the above
buttons dimmed and disabled but that is a complicated task to modify
component and then that would limit use of the component.

 What I am looking for is a way to disable (or abort) the default action
when one of those is clicked. In BeforeAction event handler I did a
switch on the Button and if a flag had been set by a previous insert or
edit I called abort. What happened is that the insert or edit was
aborted as well as the default action for the most recent button
clicked. I could change the visible buttons but that is ugly with the
control resizing. I could get rid of the refresh button since that is
not necessary but still left with rest.

Any help appreciated.

                                                Best regards


Re:Disable Default Actions: Navigator


  Testing around. TDBTrans is my own mod. The First,Prior are for
testing it.

This is on a form with two of these. When I click edit all are disabled
as needed. When clicking insert, the one I clicked on is not disabled
completely but the other one is!!! Strange. In the test app, the one
clicked is not totally disable either.
Checking enabled for each button, each one I want disabled is in fact
disabled but still show enabled in the control and function. I stepped
through the code after the last statement below and it did not go
anywhere so nothing is re-enabling the button.
This is very strange indeed. Any ideas appreciated.

procedure TDBTransNavigator.EditingChanged;
  CanModify: Boolean;
  DataState: Boolean;

  DataState := not ((FDataLink.DataSource.DataSet.State = dsEdit) or
                    (FDataLink.DataSource.DataSet.State = dsInsert));
  CanModify := Enabled and FDataLink.Active and

  Buttons[nbTFirst].Enabled       := (CanModify and DataState);
    First := nbTFirst;
  Buttons[nbTPrior].Enabled       := (CanModify and DataState);
    Prior := nbTPrior;
  Buttons[nbTNext].Enabled        := (CanModify and DataState);
    Next := nbTNext;
  Buttons[nbTLast].Enabled        := (CanModify and DataState);
    Last := nbTLast;

  Buttons[nbTInsert].Enabled      := (CanModify and DataState);
    Insert := nbTInsert;
  Buttons[nbTEdit].Enabled        := (CanModify and DataState);
    Edit := nbTEdit;
  Buttons[nbTShowDeleted].Enabled := (CanModify and DataState);
    ShowDeleted := nbTShowDeleted;
  Buttons[nbTDelete].Enabled      := (CanModify and DataState);
    Delete := nbTDelete;

  Buttons[nbTPost].Enabled        := (CanModify and (not DataState));
    Post := nbTPost;
  Buttons[nbTCancel].Enabled      := (CanModify and (not DataState));
    Cancel := nbTCancel;

  Buttons[nbTRefresh].Enabled     := (CanModify and DataState);
    Refresh := nbTRefresh;

Re:Disable Default Actions: Navigator


    This fixed above problem.

procedure TDBTransNavigator.DataChanged;
  UpEnable, DnEnable, DataState: Boolean;
  DataState := not ((FDataLink.DataSource.DataSet.State = dsEdit) or
                    (FDataLink.DataSource.DataSet.State = dsInsert));
  UpEnable := Enabled and FDataLink.Active and not
  DnEnable := Enabled and FDataLink.Active and not
  Buttons[nbTFirst].Enabled := (UpEnable and DataState);
  Buttons[nbTPrior].Enabled := (UpEnable and DataState);
  Buttons[nbTNext].Enabled := (DnEnable and DataState);
  Buttons[nbTLast].Enabled := (DnEnable and DataState);
  Buttons[nbTDelete].Enabled := Enabled and FDataLink.Active and
    FDataLink.DataSet.CanModify and DataState and
    not (FDataLink.DataSet.BOF and FDataLink.DataSet.EOF);

Other Threads