Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone!

I would like to start by saying thanks to everyone who takes some time to view this thread and try to help.

I have a Word document with a table, which has following format: 4 columns, 40 rows.

In a dialog box I have a listview that has data which goes to Word table.

In the code bellow, I check if number of items is greater than 40, and if is, I add ( NumberOfItems ) - 40 new rows, using method InsertRowBelow.

Then I type some text to test things, and it types text at proper place - current selection is the last added row.

Then I try to move up and type some text in the row before the last one, but selection moves 28 lines below the last inserted row, and types text.

If I don't insert any rows, it works OK.

I work with OLE and C++ automation.

I have used examples from these links:

How to insert text into tables in MS WORD ?[^]

My question is:

How can I fix my code to move up to the first row, after I have added new rows

C++
{
		// move from header to first row
					
		hr = AutoWrap( DISPATCH_METHOD, NULL, pSel, L"MoveDown", 0 );

		// if there are more then 40 items in listview add rows

		if( ListView_GetItemCount( GetDlgItem( hwnd, IDC_LIST1 ) ) > 40 )
			for( int i = 0; i < 
				(int)( ListView_GetItemCount( GetDlgItem( hwnd, IDC_LIST1 ) ) - 40 );
				i++ )
			{
				hr = AutoWrap( DISPATCH_METHOD, NULL, pSel, L"InsertRowsBelow", 0 );

			}

		// this is test stuff

		VARIANT xx;
		xx.vt = VT_BSTR;
		xx.bstrVal = ::SysAllocString(L"rows");

		hr = AutoWrap( DISPATCH_METHOD, NULL, pSel, L"TypeText", 1, xx );

		hr = AutoWrap( DISPATCH_METHOD, NULL, pSel, L"MoveUp", 0 );

		VARIANT x;
		x.vt = VT_BSTR;
		x.bstrVal = ::SysAllocString(L"TEST");

		hr = AutoWrap( DISPATCH_METHOD, NULL, pSel, L"TypeText", 1, x );

	}

I work in MS Visual Studio Express 2008, on Windows XP, in C++, using pure WIN32 API.

If any other information is required ( source code or something similar ), please ask for it, I will more than gladly supply it.
Posted

1 solution

C++
VARIANT wdCell, Count;
				
wdCell.vt = VT_I4;
wdCell.lVal = 12;
			
Count.vt = VT_I4;
Count.lVal = (int)( 4 * ( ListView_GetItemCount( GetDlgItem( hwnd, IDC_LIST1 ) ) - 40 )  + 1 );

hr = AutoWrap( DISPATCH_METHOD, NULL, pSel, L"MoveLeft", 2, Count, wdCell );
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900