Editor for WinForms | ComponentOne
Editor for WinForms Quick Start / Step 2 of 4: Binding C1Editor to a Document
In This Topic
    Step 2 of 4: Binding C1Editor to a Document
    In This Topic

    Now you can bind C1Editor to a document that can be saved to a file and loaded later when needed. If this document is edited within the C1Editor, the underlying XmlDocument syncs to match it.

    1. Click the View menu and select Code to switch to code view.
    2. Add the following Imports (Visual Basic) or using (C#) statements to your project so you can use abbreviated names.

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Imports System.Xml
      Imports C1.Win.C1Editor
      

      To write code in C#

      C#
      Copy Code
      using System.Xml;
      using C1.Win.C1Editor;
      
    3. Create a Form_Load event and add the following code there to create a new document and bind it to C1Editor:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
          Dim myDoc As New XmlDocument()
          C1Editor1.Document = myDoc
      End Sub
      

      To write code in C#

      C#
      Copy Code
      private void Form1_Load(object sender, EventArgs e)
      {
        XmlDocument myDoc = new XmlDocument(); 
        c1Editor1.Document = myDoc;
      }
      

    In the next step you will add code to apply a cascading style sheet to the C1Editor content.