Refresh after commit lazarus / 16-Databases ---------------------------------------------------------------------- fpcoder · 2015-10-22 17:53 A DBLookupListBox shows the names of items in a table. If a record is added, the wrong name comes up in associated DBAware controls. I have the ListSource, ListField and KeyField filled out and DataSource and DataField left empty. There is an sampleproject added, with a small sqlite database with it. To edit the properties of an item, double-click it and a form called frmItem is called up. It has only a DBEdit that shows the name and you can edit it and click OK to save. For the DBEdit to show the right value ScrollListDataSet is set to true in the query, meaning that when the frmItem form shows up, it shows the values of the record that was selected in the DBLookupListBox of the main form. So far so good, but as I said, when a new record is added and you double-click it in the listbox the DBEdit shows the name of an earlier item. Calling close and then open on the dataset makes the new record show correctly, but why isn't Refresh enough? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i qryItems.Po st;qryItems.ApplyUpdates;TX.CommitRetaining;qryItems.Refresh; Also, if an item is double-clicked and then saved, why are there so many calls to the datasource OnDataChange? (See log window of sampel app) ---------------------------------------------------------------------- balazsszekely · 2015-10-22 20:31 You need to provide a DataSource and a DataField. The DBLookupListBox represents a field in one table by displaying the value of a corresponding field in another table. In your case there is only one table(Items) no need for DBLookupListBox. Another good practice after Refresh: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  ID := qryI tems.FieldByName('item_id').AsInteger; qryItems.Post; qryItems.Refresh ; if not qryItems.Locate('item_id', ID, []) then       ShowMessage('somethings went wrong'); ---------------------------------------------------------------------- fpcoder · 2015-10-22 22:26 @GetMem: Thanks for Locate suggestion. But you suggest the DBListBox instead? That box has to be manually populated. I used DBLookUpListBox because it loads the records automaticly. Dont you think this is a valid way of using it? The goal of this exercise is to find the most efficient way of adding items and editing their properties. Maximum RAD with the least code. The idea is like this: By selecting an item in the ListBox, the current record is changed. Selecting an item in the ListBox should not change any column value anywhere, it should just move the cursor to a new record. Thats why DataSource and DataField are left empty and only ListSource is used. And when the "property editor" is brought up (frmItem) it displays the name of the current item without a line of code. It works only if ScrollListDataSet is true. A snag though, that the table has to be closed and opened for newly added items to show correctly. I hoped there was some fix. With Zeos there is no need to close and open. This was the best I could come up with, but I'm all ears what approach you guys use. ---------------------------------------------------------------------- balazsszekely · 2015-10-23 04:06 QuoteThanks for Locate suggestion.You're welcome! QuoteBut you suggest the DBListBox instead? That box has to be manually populated. I used DBLookUpListBox because it loads the records automaticly. Dont you think this is a valid way of using it? The use of TDBListBox and TDBLookupListBox is a little bit counter intuitive. It was designed for entirely other purposes then you would expect. You should switch to TDBGrid. QuoteThe goal of this exercise is to find the most efficient way of adding items and editing their properties. Maximum RAD with the least code. Just replace the listbox with a grid. Hide column items_id(usually the id is not displayed in the grid). Add the locate stuff, remove some unnecessary lines like: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   if lbItems.Count < 1 then Exit;  if lbItems.ItemIndex > -1 then That's it. It should work.