Add new entry on Listview's first position

New to Gambas? Post your questions here. No question is too silly or too simple.
Post Reply
Witchi
Posts: 11
Joined: Monday 14th February 2022 6:27pm
Location: Germany

Add new entry on Listview's first position

Post by Witchi »

Hi,

Has anyone tries to add a new entry at first position to a Listview? You can use the .Add() method, but it adds only after another entry or at the end of the list:
 ' after is a valid key within the Listview or null (at the end)
 lv.Add(mykey, mytext, mypicture, after)

If I have 5 entries on the Listview and I will add a 6th entry in front of all other entries, there isn't a method to do this. How I can achieve this?

Best regards
Witchi
vuott
Posts: 263
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: Add new entry on Listview's first position

Post by vuott »

Try... :?
Public Sub Form_Open()

  ListView1.Add("aaa", "aaa", Null, Null)
  ListView1.Add("bbb", "bbb", Null, Null)
  ListView1.Add("ccc", "ccc", Null, Null)

End

Public Sub Button1_Click()

  ListView1.Add("ddd", "ddd", Null, Null).MoveBefore("aaa")

End
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
Witchi
Posts: 11
Joined: Monday 14th February 2022 6:27pm
Location: Germany

Re: Add new entry on Listview's first position

Post by Witchi »

Yeah, that works! Thanks a lot! 8-)
User avatar
thatbruce
Posts: 168
Joined: Saturday 4th September 2021 11:29pm

Re: Add new entry on Listview's first position

Post by thatbruce »

What if "aaa" is not the first item?
Have you ever noticed that software is never advertised using the adjective "spreadable".
vuott
Posts: 263
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: Add new entry on Listview's first position

Post by vuott »

thatbruce wrote: Thursday 7th September 2023 12:48pm What if "aaa" is not the first item?
I suppose like the item with key "bbb" or "ccc" ?
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
User avatar
BruceSteers
Posts: 1582
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Add new entry on Listview's first position

Post by BruceSteers »

Use ListItem.MoveFirst() instead.

ListView1.Add("ddd", "ddd", Null, Null).MoveFirst()
https://gambaswiki.org/wiki/comp/gb.qt4 ... /movefirst
If at first you don't succeed , try doing something differently.
BruceS
vuott
Posts: 263
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: Add new entry on Listview's first position

Post by vuott »

BruceSteers wrote: Thursday 7th September 2023 9:59pm Use ListItem.MoveFirst() instead.
...exactly.
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
Post Reply