Page 1 of 1

Table with one or two columns

Posted: Thu Feb 11, 2010 11:02 pm
by hcourcelles
Hi,

I'm a new programmer with RichView and I want to do things right.

I need to provide to user a RichView that display information in one or two columns. To provide these two options I created two buttons that display "One column" or "Two column" in the Caption. What is important is that only one option can be choosen.

If they select one column, I would like that the RichView contains a table with one column and if they select two columns, the RichView would create a table containg two columns.

I've been able to create a table with one or two columns.

My problem is that if the user has already inserted information in the two columns table and they select the one column table I don't know how to copy all that was inserted inside the two columns styles included, erase all in the RichView, create the new table with one column and put inside the new table the content copy earlier.

Do you have an example on how to do this?

Best regards,

Helene

Posted: Sat Feb 13, 2010 4:00 pm
by Sergey Tkachenko
Ok, I can create an example.
But how do you want to copy document from 1-column table to 2-columns table?

Posted: Thu Feb 18, 2010 1:10 am
by hcourcelles
The content should go like this:

From one to two columns : content remains inside the first column.

From two to one column: content from column one + blank line + content from column 2 goes into column one and column two disapear.

All the style already apply to text as bold, italic, underline must be kept.

When in two columns the bestwidth for each column must be equal to 345.


Thanks for helping me.

Posted: Thu Feb 18, 2010 11:27 am
by Sergey Tkachenko

Almost working

Posted: Tue Feb 23, 2010 7:11 pm
by hcourcelles
Hello,

This is working pretty well.

I just forgot to mentioned that only one table was possible in the DBRichViewEdit. I really need the user to not be able to add more than one table with one or two columns in the DBRichViewEdit.

Thanks again for your help!

This is very cool!

Posted: Wed Feb 24, 2010 7:03 pm
by Sergey Tkachenko
Place the table in paragraph style having rvpaoNoWrap, rvpaoReadOnly, rvpaoStyleProtect in Options.


If you use TDBRichViewEdit, place this code in OnNewDocument event.

Code: Select all

var table: TRVTableItemInfo;

DBRichViewEdit1.ParaStyles.Clear;
DBRichViewEdit1.ParaStyles.Add; // normal paragraph style
with DBRichViewEdit1.ParaStyles.Add do // protected paragraph style
  Options := [rvpaoNoWrap, rvpaoReadOnly, rvpaoStyleProtect];
table := TRVTableItemInfo.CreateEx(1, 1, DBRichViewEdit1.RVData);
table.ParaNo := 1; // protected style index
DBRichViewEdit1.Clear;
DBRichViewEdit1.AddItem('', table);

Posted: Wed Feb 24, 2010 7:07 pm
by Sergey Tkachenko
The commands for changing column count in the example above were not implemented as an editing operation. So, if you use TDBRichViewEdit, you need to add code to make it work properly (see http://www.trichview.com/help/idh_examp ... edit1.html )

Code: Select all

if DBRichViewEdit1.CanChange then begin
  To1Column;
  DBRichViewEdit1.Change;
end;
The same for To2Columns.

It's almost working

Posted: Tue Apr 06, 2010 4:09 pm
by hcourcelles
Hi,

I would like to thank you for taking the time to provide me an example.

It help me implement what I needed for my client.

To make sure that the client could not insert anything else outside of the table I inserted in the OnChanging event this

If DBRichViewContenu.TopLevelEditor=DBRichViewContenu then
begin
CanEdit := False;
end;

If I understood well in another forum issue, this should mean that I am at the root of DBRichViewContenu and tells me that I am not in a table cell.

Can you tell me if I done it the right way?

The part that is not working at this time is the part for the OnNewDocument.

I'm working with a DBRichView and I encountered an error with ParaStyles.

I'm still trying to make it work. Just missing time right now.

Thanks for your kind help.

Oups! Little problem

Posted: Tue Apr 06, 2010 4:49 pm
by hcourcelles
Hello,

When I insert some bold, underline or italic style in column 2 and than try to switch to one column all the content of column number 2 is not added properly to column 1. All the content following the first style inserted (for example bold with italic) in column 2 dissapear. If I save I get an error when I try to reload.

I'm working with a DBRichView.

Do you know why and what I should do? Is it in the copying process?
It's funny because we copy without styles.

Thanks for your help.

Posted: Fri Apr 09, 2010 5:47 pm
by Sergey Tkachenko
Sorry for delay.
Can you create a simple project reproducing this problem?

Drag and drop problem after switching to two columns

Posted: Thu May 12, 2011 2:34 pm
by hcourcelles
Hello,

This is a new issue that I've been informed while using the application.

Just after switching the content of the richviewedit to two columns, if I select some text in the first column and want to drag it to the second column I get an error that force me to close the application and restart it.

But if I make a simple click in the second column and then select text from my first column and drag it, there is no error.

Should I insert some code prior to the drag and drop. Should I focus the second column just after I created the second column. If so what coding should I add to make this work?

Thanks for your help!

Posted: Thu May 12, 2011 6:17 pm
by Sergey Tkachenko
I cannot reproduce this error when using the demo http://www.trichview.com/support/files/ ... olumns.zip and the latest version of TRichView.
Can you create a simple project reproducing it?

Follow up on problem encounter

Posted: Thu May 12, 2011 7:36 pm
by hcourcelles
Hi,

I have found the problem but don't understand why it is giving an error. Maybe it is a bug. Only you will be able to tell me.

By clicking the 2 columns button with the code that you provided me, it create automatically the second columns.

I found out that just after inserting the second column

table.InsertCols(1,1,-1,False);

i've added this line of code

table.Cells[0,1].Clear;

When this line is active, the program generate an error when droping text in the second column. I've also tried it in the demo. When the line is comment no error is given when dragging and dropping.

When I'm looking at the code I understand that as I just created the second column I shouldn't have to clear it but as I've seen other example of richview table creation and it was called, I thought I should execute it as a default in my program.

Can you tell me why does this line provide an error and what I should do if I would want to keep this line active?

Best regards,

Posted: Sat May 14, 2011 7:17 am
by Sergey Tkachenko
I cannot reproduce this error after adding this line. May be you made other changes in the code?

When you add a new column, its cells contains one empty text item - it is necessary both for calculating row heights, and for the caret positioning.
When you call Cell.Clear, you remove this text item. But when you call Format, it fixes this problem by adding this text item again. So calling Cell.Clear should do nothing.