TListView.FindCaption seems to count from -1 lazarus / 31-LCL ---------------------------------------------------------------------- arneolav · 2016-02-10 22:00 I'm using FindCaption" to get items in a TListView (This is just a small list, 10 lines or so) To find the first Item, the StartIndex have to be set to -1. I had expected the first Item as 0. ListView1.Selected:=ListView1.FindCaption(- 1,'Test0',False,False,False,True);  <--- This works to find the first item ListView1.Selected:=ListView1.FindCaption(0,'Test0',False,False,False, True);  <--- This does not. The second item is found if StartIndex=0, but not 1. The third item     is found if StartIndex=1, but not 2. Is this a bug, a feature or ... ? ---------------------------------------------------------------------- JuhaManninen · 2016-02-10 22:46 Quote from: arneolav on February 10, 2016, 11:00:04 pmI'm using FindCaption" to get items in a TListView (This is just a small list, 10 lines or so) To find the first Item, the StartIndex have to be set to -1. I had expected the first Item as 0. ListView1.Selected:=ListView1.FindCaption(- 1,'Test0',False,False,False,True);  <--- This works to find the first item ListView1.Selected:=ListView1.FindCaption(0,'Test0',False,False,False, True);  <--- This does not. ... Is this a bug, a feature or ... ? Appears to be a feature. See, the fourth parameter is "Inclusive". You should make it True. The whole parameter feels useless and strange. I believe it is there for Delphi compatibility. BTW, you could have figured this out by yourself by Ctrl-clicking the method name, and then Ctrl-clicking again to get to TListItems.FindCaption and studying the code. I did that and ... good news: I also found a bug which I would not have found otherwise. Fixed in r51588. ---------------------------------------------------------------------- wp · 2016-02-10 22:48 The indexes refer to those of the SubItems of the TListItem. Since in report view there is also the Caption the indexes appear to be offset by 1. ---------------------------------------------------------------------- arneolav · 2016-02-11 07:06 Ok, Thanks guys. By the way, I'm using the ListView1.FindCaption to set focus on a selected item, This is ok when a item is selected by a mouse click, But at the program start, the first item has allways to be selected/Set focus to. Have tried this from FormCreate, FormActive and FormPaint, all are giving error "Can not SetFocus". To solve this problem I'm using a timer, start at FormCreate, and on timer interval 1, set focus is ok. Question, could this been done in a better way? ---------------------------------------------------------------------- wp · 2016-02-11 08:24 Don't understand what you're doing. You want to have the Listview focused and fail with Listview.SetFocus? Use Form.ActiveControl := Listview instead. Use ListView.ItemIndex := 0 to select the 1st list item (i.d. index 0). Set HideSelection to false to see the selected item highlighted even if the listview is not focused. ---------------------------------------------------------------------- arneolav · 2016-02-11 09:06 Thanks; Form.ActiveControl := Listview; ListView.ItemIndex := 0; This did the trick!