Recent

Author Topic: [SOLVED] DBgridview counter  (Read 599 times)

Petrus Vorster

  • Full Member
  • ***
  • Posts: 241
[SOLVED] DBgridview counter
« on: February 24, 2026, 12:23:16 pm »
Greetings all

I am updating an older project which still runs on tDBF.
I have a routine that counts the visible rows in a DBgrid and added the code for the count update in the datamodule under the DBF.AFTERDELETE and DBF.AFTERPOST events.
The counter procedure is public on form1 and the database is on a datamodule.

This works great, but there is one odd issue.
I have a little loop that correctly deletes the entire database when done, but the moment i add that counter code to the DBF.afterdelete it deletes the first entry and then nothing further.

I tried to disable controls before the delete loop, but it simply ignores it.
Code: Pascal  [Select][+][-]
  1. procedure TDm1.OuttempAfterDelete(DataSet: TDataSet);
  2. begin
  3.   form1.Updatecount;
  4. end;

I assume something is making my loop exit, but perhaps its something to do with calling a procedure on the first form from the datamodule. I am making wild guesses here.

Any guru here with an idea would be most welcome.

Regards, Peter
« Last Edit: March 02, 2026, 02:07:14 pm by Petrus Vorster »

Zvoni

  • Hero Member
  • *****
  • Posts: 3361
Re: DBgridview counter
« Reply #1 on: February 24, 2026, 12:42:00 pm »
Are you really (calculating and) displaying the VISIBLE rows, or do you display the "total" Rowcount (incl. those you'd have to scroll down/up)?
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Petrus Vorster

  • Full Member
  • ***
  • Posts: 241
Re: DBgridview counter
« Reply #2 on: February 24, 2026, 12:54:28 pm »
HI Zvoni

This is a scanner tool which scans loads of tracking numbers.
I need to put a Label with the current number of items scanned.

I have tried a number of approaches, and this seem to work reasonably well.

There is a DBnavigator with ONLY THE DELETE visible, that allow someone to delete a row for a item if that is needed.
That navigator gives me the runaround, as my counter simply doesn't update correctly when you use it to delete a record.

Remember, I have come long way, but i am still really dumb on many issues.
If you have a better plan, I will be most grateful to try it.

-Thanks  - PEter

Petrus Vorster

  • Full Member
  • ***
  • Posts: 241
Re: DBgridview counter
« Reply #3 on: February 24, 2026, 01:22:18 pm »
I think i am going to avoid that datamodule commands on the delete.

A bit more testing then...

-Peter

Zvoni

  • Hero Member
  • *****
  • Posts: 3361
Re: DBgridview counter
« Reply #4 on: February 24, 2026, 01:30:21 pm »
If you just want to display the total number of records in the DBGrid in a separate label.....
Code: Pascal  [Select][+][-]
  1. //Everytime after an Insert or Delete
  2. MyDBGrid.DataSource.DataSet.Refresh;
  3. myLabel.Caption:=MyDBGrid.DataSource.DataSet.RecordCount.ToString;
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Petrus Vorster

  • Full Member
  • ***
  • Posts: 241
Re: DBgridview counter
« Reply #5 on: February 24, 2026, 01:59:40 pm »
Hi

Can the admin please remove this stupid post?
I have found the most simple way I have overlooked for how long and its working perfectly.

I feel really silly.

-Peter :-[

Petrus Vorster

  • Full Member
  • ***
  • Posts: 241
Re: DBgridview counter
« Reply #6 on: February 24, 2026, 02:00:12 pm »
Zvoni, yours is even better.

-Peter

 

TinyPortal © 2005-2018