Page 1 of 1
Edit Line of a Cell
Posted: Wed Nov 15, 2006 2:06 pm
by jwkerns
I loop thru and load x number of cells in my richview.
I want to run another loop afterwards and update a line in each cell.
So if I wanted to say add some text to the beginning of the first line how would I do this? Would like an example. Thanks
Posted: Wed Nov 15, 2006 4:53 pm
by Sergey Tkachenko
Inserting text not at the end of document is not possible using documented methods. Well, I can make an example of inserting text in the beginning of each cell, but may be this will be not what you need.
Can you explain what to you want to implement with more details?
Actually that will suffice
Posted: Thu Nov 16, 2006 6:35 pm
by jwkerns
Yes that would help.
Basically each cell is loaded with a question. Because we randomly present the questions I don't know the question number before hand.
So after my cells are populated , I reloop thru then and update the current contents.
So for instance , if I have a cell that says 'What is 2 + 2?' then I want to edit the first line in the cell with a question number to look like '1: What is 2 + 2?'.
Posted: Fri Nov 17, 2006 12:30 am
by shmp
Just an idea.
This is not a very complicated task. You could create a TStringlist for all the questions. Loop through and gather all the questions by adding each one to the StringList and clearing the cells where the question was copied.
Make another loop and this time, random select the question from the TStringList, place it in the cell then delete it from the TStringList.
The next random means that there is less question until the TStringList has only two questions left.
The last question in the TStringList is for the last cell.
By clearing the cells means that you can add the question instead of inserting it.
Hope this idea is good for you.
Good luck.
Posted: Fri Nov 17, 2006 12:46 am
by shmp
Or you could offset before item then insert the number.
Posted: Sun Nov 19, 2006 7:01 pm
by Sergey Tkachenko
If you just need to modify the existing text (not to insert new paragraphs or text of different font), it is very simple.
This code adds numbers to the first columns of each table in the document (nested tables are ignored).
Code: Select all
var i, r, idx: Integer;
table: TRVTableItemInfo;
for i := 0 to rv.ItemCount-1 do
if rv.GetItemStyle(i)=rvsTable then begin
table := TRVTableItemInfo(rv.GetItem(i));
idx := 1;
for r := 0 to table.RowCount-1 do
if (table.Cells[r,0]<>nil) and
(table.Cells[r,0].GetRVData.GetItemStyle(0)>=0) then begin
s := table.Cells[r,0].GetRVData.GetItemTextA(0);
table.Cells[r,0].GetRVData.SetItemTextA(0, IntToStr(idx)+': '+s);
inc(idx);
end;
end;
rv.Format;