Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / May 2008

Tip: Looking for answers? Try searching our database.

Wrapper class for ContentControls (implementing Text property)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jens Gyldenkærne Clausen - 09 May 2008 14:09 GMT
Hi group. I am working with ContentControls in Word 2007 and have now
(once again) stumbled upon something peculiar.

The basic Microsoft.Office.Tools.Word.ContentControl class - the type
that can represent all eight types of content controls - has lots of
members, some of them specific to certain types (such as
DateCalendarType and ShowingPlaceholderText). But one very important
property is missing - a simple .Text property to expose the textual
content in a PlainTextContentControl, RichTextContentControl,
DatepickerContentControl etc. Why is that??

I'm programming a solution where I need to access all content controls
in a Word template - and for every textual content control be able to
read and set the content. This seems to be frustratingly difficult. I'm
now trying to write a wrapper class implementing the missing .Text
property - but in doing that, I discovered that 1) the ContentControl
class is sealed, making it impossible to expand; 2) the
ContentControlBase class has a note stating that one shouldn't derive
own types from it.

What would be "best practice" in this case? I'm thinking of

A) Ignore the note and derive from ContentControlBase since I need a
handle to the Text property

B) Drop the wrapper class and handle the Text set/get with type probing
and duplicated internal code

C) Try to implement some kind of cast functionality, using the
PlainTextContentControl as the lowest denominator (in my programmatic
manipulations I have no need for methods/properties other than the ones
supported by a PlainTextContentControl.

Reference link:
http://msdn.microsoft.com/library/microsoft.office.tools.word.contentcontrol(en-
us).aspx


Signature

Jens Gyldenkærne Clausen
CBS IT
Svar venligst i gruppen.

Jay Freedman - 09 May 2008 15:10 GMT
Hi Jens,

Try using the control's .Range.Text property. I think it will do what you
want -- at least, it appears to do so in VBA.

Signature

Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

> Hi group. I am working with ContentControls in Word 2007 and have now
> (once again) stumbled upon something peculiar.
[quoted text clipped - 31 lines]
> Reference link:
> http://msdn.microsoft.com/library/microsoft.office.tools.word.contentcontrol(en-
us).aspx
Jens Gyldenkærne Clausen - 09 May 2008 21:42 GMT
> Try using the control's .Range.Text property. I think it will do what you
> want -- at least, it appears to do so in VBA.

Well - the .Range property does indeed provide a handle to the textual
content in the control; but unfortunately it is a readonly property. I
need to be able to set the text as well as reading it (this is working
fine in my current code where I'm only working with
PlainTextContentControls, but the final template will have a mixture of
PlainText-, RichText- and DatePickerContentControls. For all of these
control types the same basic action (using get and set at the text
content in the control) is to be added on the Enter/Exit events.

To make things even more confusing, there is a note in the
documentation of the ContentControl.Range property referring to the
(nonexisting) .Text property:

| To access only the text that is displayed in the ContentControl, use
| the Text() property.

http://msdn.microsoft.com/library/microsoft.office.tools.word.contentcontrol.range

Who ate my Text property?

Signature

Jens Gyldenkærne Clausen
CBS IT
Svar venligst i gruppen.

Scott McPhillips [MVP] - 09 May 2008 22:09 GMT
>> Try using the control's .Range.Text property. I think it will do what you
>> want -- at least, it appears to do so in VBA.
>
> Well - the .Range property does indeed provide a handle to the textual
> content in the control; but unfortunately it is a readonly property.

No, it is not read-only:
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.range.text.aspx

Signature

Scott McPhillips [VC++ MVP]

Jens Gyldenkærne Clausen - 09 May 2008 22:19 GMT
> No, it is not read-only:
> http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.range.text.aspx

Ah - the range itself is readonly but the Range.Text is not. Excellent
- this looks like a perfect solution. Will try it out some time after
the pentecost holiday.

Thanks a lot for the answer.

Signature

Jens Gyldenkærne Clausen
CBS IT
Svar venligst i gruppen.


Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.