I have two DB grids on a form and one has a vertical scrollbar and the other doesn't, even when the DataSource query returns more results than the Grid's visible rows.
Why is the vertical scrollbar on the TDBGrid
not displayed?
[Update] Delphi XE2 starter, using AnyDac.
When I first start the program, the DB grid does have a vertical scrollbar, but later it vanishes and I have narrowed it down, but still cannot understand how to correct teh problem.
I have two MySql tables and two DBgrids. One is an overview of all test runs and the other contains details of measurements taken during a test run. When the user clicks on a row of the "summary" grid, I update a parameter of the query of the "details" grid. This works and does not remove the scroll bar.
The problem comes when I start a new tets run and insert a new row into the "summary" table - the scroll bar of the "details" table vanishes!
mysql> describe test_runs;
+------------------+-------------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+-------------+------+-----+-------------------+----------------+
| run_id | int(11) | NO | PRI | NULL | auto_increment |
| start_time_stamp | timestamp | NO | | CURRENT_TIMESTAMP | |
| end_time_stamp | timestamp | YES | | NULL | |
| description | varchar(64) | YES | | NULL | |
+------------------+-------------+------+-----+-------------------+----------------+
4 rows in set (0.02 sec)
mysql> describe measurements;
+------------------------+-----------+------+-----+-------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+-----------+------+-----+-------------------+-------+
| run_id | int(11) | NO | MUL | NULL | |
| measurement_time_stamp | timestamp | NO | | CURRENT_TIMESTAMP | |
| ph | float | NO | | NULL | |
| conductivity | float | NO | | NULL | |
| cod | float | NO | | NULL | |
+------------------------+-----------+------+-----+-------------------+-------+
5 rows in set (0.04 sec)
mysql>
The AnyDac queries are, repectively,
SELECT
run_id,
start_time_stamp,
end_time_stamp,
CONCAT(CONCAT(CONCAT(CONCAT(LPAD(EXTRACT(HOUR FROM timediff(end_time_stamp,start_time_stamp)), 2, '0'), ":"),LPAD(EXTRACT(MINUTE FROM timediff(end_time_stamp,start_time_stamp)), 2, '0'), ":"), LPAD(EXTRACT(SECOND FROM timediff(end_time_stamp,start_time_stamp)), 2, '0'))) AS duration,
description
FROM
test_runs
ORDER BY
start_time_stamp
DESC
and
SELECT
run_id,
measurement_time_stamp,
ROUND(ph, :float_precision) as ph,
ROUND(conductivity, :float_precision) as conductivity,
ROUND(cod, :float_precision) as cod
FROM
measurements
WHERE
run_id=:run_id
ORDER BY
measurement_time_stamp
DESC
As you can see, there is referce in the measurements
table to the test_runs
table
When I execute the following SQL, the scroll bar of the measurements table vanishes:
INSERT INTO
test_runs (start_time_stamp, description)
VALUES
(CURRENT_TIMESTAMP, "<Currently running test>");
SELECT LAST_INSERT_ID() AS run_id
Can anyne tell me what I am doing wrong? Thanks a 0x000F4240
[Update] Once again, the problem is that when I add a row to the test_runs
table, the vertical scroll bar of the DB grid which reflects the query of the measurements
table vanishes.
So, somehow, one DB grid/dataset/table is affecting the otherDB grid.
The data in the actual MySql database are fine.
The problem occurs no matter whether I use a command to INSERT INTO
and two decicated queries (with SQL fixed at design time and never changed) or if I use @kobik suggestion to dataset.append
.
The database contents are fine, the DB contents are correct, when I click on the summary test_runs
DB grid the contents of the details measurements
DB grid are correctly updated.
The only problem is that inserting a row into the table of the test_runs
query causes the scroll bar to vanish from the DB grid of the measurements
DB grid.
When I comment that out, I can click the test_runs
DB grid and swap between test runs without the scroll bar vanshing, but can never get back to the current test, because there is no entry for it in the DB grid.
When I first start a new test dataset
.RecordCount` is, of course, zero - which might cause the scrollbar to vanish?
However, as measurements are made (every one second, timer based), I have checked and the value of dataset
.RecordCount` increments, so here ought to be a scrollbar after the second measurement? Or do I have to force it to appear once the control has decided that it was not needed? (Invalidating the DB grid did not cause the missing scrollbar to appear)
[Update]
As suggested by @kobik I have made run_id a primary, auto increment key on the test_runs
table and an index on the measurements
table. I have updated the table details given above. I have also set the mastersource
of the query which populates the test drun DB grid to the datasource of the test runs "summary" DB grid's query.
I delete the databse (my code auotmatically recreates it on first run). At first, neither DB grid had a vertical scroll bar, becaus they were both empty. When I added a first test the "summary" DB grid had no scroll bar, because it had only 1 entry, the "details" DB grid had no scrollbar at 0 and entries and the scroll bar appeared with the 2nd set of measurements.
I added a second test run and the "sumamry" DB grid had a scroll bar as it now had two entries, but as soon as I added the second entry to the summary, the scroll bar vanished from the "details" DB grid (which it did not do when there was a single test run), no matter how many entries it had (I breakpoint as each set of measuements is added and check measurementsQuery.RecordCount
and see it go 0, 1, 2 ...)
It is worth pointing out that this only happens when I add a new test run (other than the first)). If I launch the program, both DB grids have scroll bars as expectd (> 1 entries). And I can click or mousewheel through the summary to disaply the details of the coresponding test run. The scroll bar never vanishes - until I add a new test run, which inserts a row ito the summary DB grid.
[Update]
Please see https://stackguides.com/questions/15399769/why-is-the-vertical-scrollbar-on-a-tdbgrid-not-displayed-redux
ShowScrollbar(DBGrid.Handle, SB_VERT, true)
in the overridenUpdateScrollbar
. – Guillem Vicensis hardcoded
and depends on displayed rows and it's not so easy to hide it. – TLamaINSERT
on a datasource linked with your DB grid. Though I'm not saying it's the reason of what you're describing, but might be. – TLama