title: Why is the vertical Scrollbar on a TDBGrid not displayed?
body: <p>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.</p>
  
  <p>Why is the vertical scrollbar on the <code>TDBGrid</code> not displayed? </p>
  
  <hr>
  
  <p>[Update] Delphi XE2 starter, using AnyDac.</p>
  
  <p>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.</p>
  
  <p>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. </p>
  
  <p>The problem comes when I start a new tets run and insert a new row into the "summary" table - the scroll bar of the <strong>"details"</strong> table vanishes!</p>
  
  <pre><code>mysql&gt; 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&gt; 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&gt;
  </code></pre>
  
  <p>The AnyDac queries are, repectively,</p>
  
  <pre><code>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
  </code></pre>
  
  <p>and</p>
  
  <pre><code>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
  </code></pre>
  
  <p>As you can see, there is referce in the <code>measurements</code> table to the <code>test_runs</code> table</p>
  
  <p>When I execute the following SQL, the scroll bar of the measurements table vanishes:</p>
  
  <pre><code>INSERT INTO 
     test_runs (start_time_stamp, description) 
  VALUES 
     (CURRENT_TIMESTAMP, "&lt;Currently running test&gt;"); 
  
  SELECT LAST_INSERT_ID() AS run_id
  </code></pre>
  
  <p>Can anyne tell me what I am doing wrong? Thanks a 0x000F4240</p>
  
  <hr>
  
  <p>[Update] Once again, the problem is that when I add a row to the <code>test_runs</code> table, the vertical scroll bar of the DB grid which reflects the query of the <code>measurements</code> table vanishes.</p>
  
  <p>So, somehow, one DB grid/dataset/table is affecting the otherDB grid.</p>
  
  <p>The data in the actual MySql database are fine.
  The problem occurs no matter whether I use a command to <code>INSERT INTO</code> and two decicated queries (with SQL fixed at design time and never changed) or if I use @kobik suggestion to <code>dataset.append</code>.</p>
  
  <p>The database contents are fine, the DB contents are correct, when I click on the summary <code>test_runs</code> DB grid the contents of the details <code>measurements</code> DB grid are correctly updated.</p>
  
  <p>The only problem is that inserting a row into the table of the <code>test_runs</code> query  causes the scroll bar to vanish from the DB grid of the <code>measurements</code> DB grid.</p>
  
  <p>When I comment that out, I can click the <code>test_runs</code> DB grid and swap between test runs <strong>without the scroll bar vanshing</strong>, but can never get back to the current test, because there is no entry for it in the DB grid.</p>
  
  <p>When I first start a new test <code>dataset</code>.RecordCount` is, of course, zero - which might cause the scrollbar to vanish?</p>
  
  <p>However, as measurements are made (every one second, timer based), I have checked and the value of <code>dataset</code>.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)</p>
  
  <hr>
  
  <p>[Update]
  As suggested by @kobik I have made run_id a primary, auto increment key on the <code>test_runs</code> table and an index on the <code>measurements</code> table. I have updated the table details given above. I have also set the <code>mastersource</code> of the query which populates the test drun DB grid to the datasource of the test runs "summary" DB grid's query.</p>
  
  <p>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.</p>
  
  <p>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 <strong>did not do</strong> 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 <code>measurementsQuery.RecordCount</code> and see it go 0, 1, 2 ...)</p>
  
  <p>It is worth pointing out that this only happens when I add a new test run (<strong>other than the first</strong>)). 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.</p>
  
  <p>[Update]<br>
  Please see <a href="https://stackoverflow.com/questions/15399769/why-is-the-vertical-scrollbar-on-a-tdbgrid-not-displayed-redux">https://stackoverflow.com/questions/15399769/why-is-the-vertical-scrollbar-on-a-tdbgrid-not-displayed-redux</a></p>
  
  <hr>