ComboBox Readonly Error lazarus / 16-Databases ---------------------------------------------------------------------- Bartlebee · 2014-03-03 17:45 Lazarus v1.0.12 I am making an application that goes through the rows of a database as you click the 'next' button. One of my fields is an ID number that is shown in the comboBox. What I liked was that the comboBox not only showed the user what ID number they're currently on, but when you click to see the dropdown, it will show you all the distinct id numbers in the table, and upon click take you there. So it is a good filter. Upon start, the comboBox shows the ID # of 1.1, and works as planned. I recently decided that for my purposes I'd prefer a readonly comboBox (basically a dropdown selectBox). But upon opening my app, the comboBox shows nothing. I click 'next' and it is still blank. I do not understand. In form create I set the combobox.text:=ID#, why is it blank? (I did not have this problem when it wasn't readonly) When I click once on the readonly comboBox it gives me all my choices and highlights the ID I'm currently on (in this case 1.1) and the program works 100% as planned. Works exactly as it used to. But first I need to click on the readonly comboBox when I first start the program. I want, upon opening my program, for the comboBox to automatically show the ID # without the need for the user to have to click on the comboBox first. Suggestions? ---------------------------------------------------------------------- taazz · 2014-03-03 23:03 Code: [Select]comboBox1.ItemIndex := combobox1.Items.IndexOf(ID#); ---------------------------------------------------------------------- Bartlebee · 2014-03-04 20:11 Thank you taazz for the response. It seems to simplify some of my code, but doesn't really address my problem. (at least not from what I could see) My problem is with the read-only combobox. If I set in the procedure form create that combobox1.text:='blueberries'; and open the program, I will see an empty combobox. I could make 'blueberries' the only item in the combobox, and it would show up automatically in the regular combobox but not in the readonly. (i'd have to click on the dropdown and select it first. ) Is there anyway I can get the first item on the dropdown to show automatically on the readonly combobox? ---------------------------------------------------------------------- mangakissa · 2014-03-04 21:47 What's a readonly combobox? AFAIK the DBcombobox is set to a datafield of a dataset and the items are manually filled in. Another thing is a DBLookupcombox. Has the same functionality, read its item from another table. The keyfield will be found in the itemlist and show your item as text and not an id. ---------------------------------------------------------------------- taazz · 2014-03-05 00:38 Quote from: Bartlebee on March 04, 2014, 09:11:36 pmThank you taazz for the response. It seems to simplify some of my code, but doesn't really address my problem. (at least not from what I could see) My problem is with the read-only combobox. If I set in the procedure form create that combobox1.text:='blueberries'; and open the program, I will see an empty combobox. I could make 'blueberries' the only item in the combobox, and it would show up automatically in the regular combobox but not in the readonly. (i'd have to click on the dropdown and select it first. ) Is there anyway I can get the first item on the dropdown to show automatically on the readonly combobox? Setting the itemindex property to the item you want selected should select that item in the combobox if it is not then there is some other problem. Please provide a minimalistic sample application that show the problem for us to test, also make sure you use the latest lazarus release for tests. ---------------------------------------------------------------------- engkin · 2014-03-05 03:40 Quote from: Bartlebee on March 04, 2014, 09:11:36 pmIs there anyway I can get the first item on the dropdown to show automatically on the readonly combobox? Yes: Code: [Select]  if ComboBox1.Items.Count > 0 then  //has some items?     ComboBox1.ItemIndex := 0;       //show the first item    To show blueberries: Code: [Select]  ComboBox1.Items.Add('blueberries');  //add an item   ComboBox1.ItemIndex := ComboBox1.Items.IndexOf('blueberries') ;  //choose it