1. Computing & Technology

Discuss in my forum

How to Enable the Refresh button on a DBNavigator for ReadOnly Datasets

By , About.com Guide

When using the TDBNavigator component with read-only datasets, the Refresh button is disabled by design. In many situations you will have a read-only dataset displayed in a DBGrid, connected to a DBNavigator where DataSet's (TxxxTable or TxxxQuery) Refresh method is expected and "legal".

Here's how to re-enable the DBNavigator's Refresh button:

  1. Expose the Buttons property of the DBNavigator by using the protected hack method. First we create a class to access the protected members of a DBNavigator:

    TDBNavigatorEx = class(TDBNavigator) ;

  2. Set Enable = true for the Refresh button inside the dataset's OnOpen event handler.

    TDBNavigatorEx(DBNavigator).Buttons[nbRefresh].Enabled := TRUE ;

    Note: "DBNavigator" is the name of the DBNavigator component attached to a readonly datasource/dataset.

That's it. Now you can use the Refresh button even on a readonly dataset.

Delphi tips navigator:
» Implementing custom sorting for a TListView component
« Placing a Form inside a TabSheet of a TPageControl

©2012 About.com. All rights reserved.

A part of The New York Times Company.