Page 1 of 1

Special Handling for Tables

Posted: Tue Jun 01, 2010 1:20 pm
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?

Posted: Tue Jun 01, 2010 4:33 pm
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;

Posted: Tue Jun 01, 2010 6:11 pm
by dc3_dcfl
Thank-you, Worked Perfectly

Posted: Wed Jun 02, 2010 8:42 pm
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.

Posted: Thu Jun 03, 2010 7:56 am
by Sergey Tkachenko
Call RVRuler1.UpdateRulerMargins in the same events, to assign margins from DBRichViewEdit to the ruler.

Posted: Thu Jun 03, 2010 1:30 pm
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.

Posted: Thu Jun 03, 2010 2:31 pm
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.

Posted: Thu Jun 03, 2010 6:46 pm
by Sergey Tkachenko
Do you change ruler margins after loading a document from field?

Posted: Thu Jun 03, 2010 7:00 pm
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.

Posted: Thu Jun 03, 2010 7:29 pm
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.

Posted: Fri Jun 04, 2010 7:24 pm
by Sergey Tkachenko
Do you have ruler on the main form, or in MDI child form?

Posted: Mon Jun 07, 2010 12:56 pm
by dc3_dcfl
Both the vertical and horizontal rulers are on the MDI child.

Posted: Mon Jun 07, 2010 3:43 pm
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?