Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / VS Tools for Office / April 2007

Tip: Looking for answers? Try searching our database.

Office 2007 How to remove a dynamically added ContentControl?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
PL - 17 Apr 2007 17:11 GMT
// Startup
myTable.Rows.Add(ref this.missing);
myTable.Rows.Last.Cells[1].Range.Text = "Phone:";
myTable.Rows.Last.Cells[2].Select();
PlainTextContentControl ptcc;
ptcc = this.Controls.AddPlainTextContentControl("Phone");
ptcc.Title = "Phone";
ptcc.PlaceholderText = "Enter your phone here";
ptcc.LockContentControl = true;

// Button_Click
PlainTextContentControl ptcc;
foreach (object ctrl in this.Controls)
{
   ptcc = ctrl as PlainTextContentControl;
   if ((ptcc != null) && (ptcc.Title == "Phone"))
   {
       ptcc.LockContentControl = false;
       this.Controls.Remove(ptcc);
       break;
   }
}

The above code runs without error, but the PlainTextContentControl is not
removed.  Investigated it and found that the dynamic content control is not
a member of this.Controls collection!!!  How to remove it in code?

Signature

S.Y. Paul Lai

PL - 17 Apr 2007 17:39 GMT
OK, I found the answer:
ptcc.InnerObject.Delete(true);

Microsoft.Office.Tools.Word.PlainTextContentControl
doesn't provide a method to delete itself (STUPID!!!)

Need to use it's Interop class
Microsoft.Office.Interop.Word.ContentControl.Delete(bool DeleteContents)

Signature

S.Y. Paul Lai

> // Startup
> myTable.Rows.Add(ref this.missing);
[quoted text clipped - 22 lines]
> removed.  Investigated it and found that the dynamic content control is not
> a member of this.Controls collection!!!  How to remove it in code?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
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.