Special Handling for Tables

General TRichView support forum. Please post your questions here
Post Reply
dc3_dcfl
Posts: 33
Joined: Sat Jan 30, 2010 12:45 am

Special Handling for Tables

Post by dc3_dcfl »

When the first item in a dbrichview document is a table, I want to automatically position the cursor within the first cell at the first character. If the first item is not a table, I want the default behavior.

How can I accomplish this in my formcreate method?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

You can use Table.AfterScroll event:

Code: Select all

procedure TForm1.Table1AfterScroll(DataSet: TDataSet);
begin
  if (DBRichViewEdit1.ItemCount>0) and (DBRichViewEdit1.GetItemStyle(0)=rvsTable) then
    TRVTableItemInfo(DBRichViewEdit1.GetItem(0)).EditCell(0,0);
end;
dc3_dcfl
Posts: 33
Joined: Sat Jan 30, 2010 12:45 am

Post by dc3_dcfl »

Thank-you, Worked Perfectly
dc3_dcfl
Posts: 33
Joined: Sat Jan 30, 2010 12:45 am

Post by dc3_dcfl »

One more issue I'm encountering.

When I have an empty document, the cursor sometimes (unpredictable) does not place itself within the margins I've created with the rulers (1 inch left and right, and 1 inch top and bottom). Instead the cursor shows up in the upper left corner.

When I start typing, the cursor jumps to the correct position, but when I import a document, if the first item is a bullet, the bullet is to the left of my left margin, which I must then reset manually.

Any idea why this is happening?

Thanks in advance.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Call RVRuler1.UpdateRulerMargins in the same events, to assign margins from DBRichViewEdit to the ruler.
dc3_dcfl
Posts: 33
Joined: Sat Jan 30, 2010 12:45 am

Post by dc3_dcfl »

I'm still getting this behavior.

Here is the code:

if (DBRichViewEdit1.ItemCount > 0) and (DBRichViewEdit1.GetItemStyle(0) = rvsTable) then
TRVTableItemInfo(DBRichViewEdit1.GetItem(0)).EditCell(0,0)
else
DBRichViewEdit1.SetSelectionBounds (0,DBRichViewEdit1.GetOffsBeforeItem(0), 0, DBRichViewEdit1.GetOffsBeforeItem(0));
rvRuler1.UpdateRulerMargins;
rvRuler2.UpdateRulerMargins;

(if the first item in document is a table, move to the 1st cell, 1st character, else move to the beginning of the first paragraph, then as you instructed, add the UpdateRulerMargins.
dc3_dcfl
Posts: 33
Joined: Sat Jan 30, 2010 12:45 am

Post by dc3_dcfl »

I've been testing the application a bit more, and find that even when the document has text, in some instances the cursor positions itself upper left corner not within the margins.

Again, this is random, I can open up a document with the cursor in the correct position many times, then the next time, it won't be.

Even with the cursor in the incorrect position, typing snaps the cursor to the correct position.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Do you change ruler margins after loading a document from field?
dc3_dcfl
Posts: 33
Joined: Sat Jan 30, 2010 12:45 am

Post by dc3_dcfl »

No, I set all the ruler properties from the object inspector. No code manipulations of the ruler other than the UpdateRulerMargins you suggested.
dc3_dcfl
Posts: 33
Joined: Sat Jan 30, 2010 12:45 am

Post by dc3_dcfl »

Another hint...

Just figured out the pattern on when the cursor shows up in the wrong position.

My application is an MDI application. Each time my MDI frame creates a new form, the new one shows up offset down and to the right (as defined by windows). After a few iterations of creating forms (with the DBrichviewedit on it), the incorrectly placed cursor starts to occur. When the cycle is complete, and the new form once again starts at the upper left of my MDI frame, the cursor once again obeys the margins.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Do you have ruler on the main form, or in MDI child form?
dc3_dcfl
Posts: 33
Joined: Sat Jan 30, 2010 12:45 am

Post by dc3_dcfl »

Both the vertical and horizontal rulers are on the MDI child.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

In this case, if both a ruler and an editor are on a child form, I do not understand how the position of the child form may affect the caret position.
Can you create a simple project reproducing this problem and send it to me?
Post Reply