How to get newly inserted item??

General TRichView support forum. Please post your questions here
Post Reply
Posts: 1
Joined: Fri Mar 29, 2019 2:33 pm

How to get newly inserted item??

Post by kaka »

Right after call AddNLTag() how can I get the correct ItemInfo? rve.GetCurrentItem? :?: :?: :?:


Sergey Tkachenko
Site Admin
Posts: 14897
Joined: Sat Aug 27, 2005 10:28 am

Re: How to get newly inserted item??

Post by Sergey Tkachenko »

Add*** methods append data to the end of the document.
If this method adds a single item (like rv.AddNLTag), you can access it using the index rv.ItemCount - 1.
For example:

Code: Select all

rv.AddNLTag('Hello', 0, 0, 'greetings');
Caption := rv.GetItemText(rv.ItemCount - 1) + rv.GetItemTag(rv.ItemCount - 1);
If you call Add*** method that can add multiple items (such as AddTextNL), you can compare the value of ItemCount before and after to calculate how many items are added to the end.

You cannot use GetCurrent*** methods to get information about items added by Add*** methods.
GetCurrent*** methods return information about the item at the caret position.
After calling Add*** methods the document is unformatted until you call Format, and the caret position is undefined.
GetCurrent*** methods can be used after editing methods for insertion (Insert***) - but only if this insertion was successful. Insertion may fail because of text protection, or if multiple table cells were selected.
Most insertion methods return True on success:

Code: Select all

if rve.InsertPicture(…) then

Post Reply