# Grouping Undo Steps with TX Text Control

> TX Text Control manages undo history through snapshots and message queues. Applying multiple formatting changes via the Selection object registers as one undo step. For grouped operations, a temporary ServerTextControl processes edits offline and reloads them as a single undo entry.

- **Author:** Bjoern Meyer
- **Published:** 2014-12-22
- **Modified:** 2026-07-17
- **Description:** TX Text Control manages undo history through snapshots and message queues. Applying multiple formatting changes via the Selection object registers as one undo step. For grouped operations, a temporary ServerTextControl processes edits offline and reloads them as a single undo entry.
- **2 min read** (279 words)
- **Tags:**
  - Tutorial
  - Undo
- **Web URL:** https://www.textcontrol.com/blog/2014/12/22/grouping-undo-steps-with-tx-text-control/
- **LLMs URL:** https://www.textcontrol.com/blog/2014/12/22/grouping-undo-steps-with-tx-text-control/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2014/12/22/grouping-undo-steps-with-tx-text-control/llms-full.txt

---

The undo and redo history is a very complex internal process that utilizes snapshots, message queues and internal grouping mechanisms to provide a smooth undo experience. For example, while typing, a single undo step is not the single key press, but the complete text until a new action such as a specific formatting is applied.

Internally, complex and highly optimized history lists are generated to save memory and keep up the performance.

In case, the Selection object and its direct properties should be manipulated, these changes are counted as 1 undo step. The following code shows how to apply various formatting options to the current selection with only 1 undo step in the history:

```
TXTextControl.Selection mySelection = new TXTextControl.Selection();

mySelection.Bold = true;
mySelection.ListFormat.Type = TXTextControl.ListType.Numbered;
mySelection.ParagraphFormat.Alignment =
    TXTextControl.HorizontalAlignment.Center;

// 1 undo step
textControl1.Selection = mySelection;
```

In case, you want to group several, more complex undo steps in one, you can use a temporary, invisible ServerTextControl to manipulate the selection or the complete document. The following code shows how to insert and format a table into the current selection:

```
byte[] data;

// save the current selection in a byte array
textControl1.Selection.Save(out data,
    TXTextControl.BinaryStreamType.InternalUnicodeFormat);

// create a temporary ServerTextControl to manipulate the selection
using (TXTextControl.ServerTextControl tx =
    new TXTextControl.ServerTextControl())
{
    tx.Create();
    tx.Load(data, TXTextControl.BinaryStreamType.InternalUnicodeFormat);

    // do \'something\' here
    tx.Tables.Add(5, 5, 13);

    foreach (TXTextControl.TableCell cell in tx.Tables.GetItem(13).Cells)
    {
        cell.CellFormat.LeftBorderWidth = 1;
        cell.Text = "new text";
    }

    // save out the manipulated selection
    tx.Save(out data, TXTextControl.BinaryStreamType.InternalUnicodeFormat);
}

// load the manipulated selection  back into the TextControl
// this \'loading\' will be 1 undo step
textControl1.Selection.Load(data,
    TXTextControl.BinaryStreamType.InternalUnicodeFormat);
```

---

## About Bjoern Meyer

As CEO, Bjoern is the visionary behind our strategic direction and business development, bridging the gap between our customers and engineering teams. His deep passion for coding and web technologies drives the creation of innovative products. If you're at a tech conference, be sure to stop by our booth - you'll most likely meet Bjoern in person. With an advanced graduate degree (Dipl. Inf.) in Computer Science, specializing in AI, from the University of Bremen, Bjoern brings significant expertise to his role. In his spare time, Bjoern enjoys running, paragliding, mountain biking, and playing the piano.

- [LinkedIn](https://www.linkedin.com/in/bjoernmeyer/)
- [X](https://x.com/txbjoern)
- [GitHub](https://github.com/bjoerntx)

---

## Related Posts

- [New Text Control HTML5 Ad Campaign](https://www.textcontrol.com/blog/2014/12/21/new-text-control-html5-ad-campaign/llms.txt)
- [Windows Forms Tutorial: Create Your First Windows Forms C# Application](https://www.textcontrol.com/blog/2024/08/26/windows-forms-tutorial-create-your-first-windows-forms-csharp-application/llms.txt)
- [How to Mail Merge MS Word DOCX Documents in ASP.NET Core C#](https://www.textcontrol.com/blog/2023/10/16/how-to-mail-merge-ms-word-docx-documents-in-aspnet-core-csharp/llms.txt)
- [Creating an Angular Document Editor Application with a Node.js WebSocket Server](https://www.textcontrol.com/blog/2023/08/24/creating-an-angular-document-editor-application-with-a-nodejs-websocket-server/llms.txt)
- [Adding SVG Watermarks to Documents](https://www.textcontrol.com/blog/2022/01/28/adding-svg-watermarks-to-documents/llms.txt)
- [Using MailMerge in ASP.NET Core 6 Web Applications](https://www.textcontrol.com/blog/2022/01/27/using-mailmerge-in-aspnet-core-6-web-applications/llms.txt)
- [DocumentViewer for React Prerelease](https://www.textcontrol.com/blog/2020/10/27/document-viewer-for-react-prerelease/llms.txt)
- [New DocumentViewer Signature Tutorial Sample](https://www.textcontrol.com/blog/2020/08/18/new-documentviewer-signature-tutorial-sample/llms.txt)
- [Creating an ASP.NET MVC DocumentViewer Application With Razor](https://www.textcontrol.com/blog/2020/01/01/creating-an-aspnet-mvc-documentviewer-application-with-razor/llms.txt)
- [Creating Your First Windows Forms Application with C#](https://www.textcontrol.com/blog/2020/01/01/creating-your-first-windows-forms-application-with-csharp/llms.txt)
- [Creating Your First WPF Application](https://www.textcontrol.com/blog/2020/01/01/creating-your-first-wpf-application/llms.txt)
- [Creating a WPF Ribbon Application](https://www.textcontrol.com/blog/2020/01/01/creating-a-wpf-ribbon-application/llms.txt)
- [Integrate Document Editing into any HTML Client using the HTML Widget](https://www.textcontrol.com/blog/2020/01/01/integrate-document-editing/llms.txt)
- [Creating an ASP.NET MVC Application With Razor](https://www.textcontrol.com/blog/2020/01/01/creating-an-aspnet-mvc-application-with-razor/llms.txt)
- [Creating A Windows Forms Ribbon Application](https://www.textcontrol.com/blog/2020/01/01/creating-a-windows-forms-ribbon-application/llms.txt)
- [Creating Your First ASP.NET Reporting Application](https://www.textcontrol.com/blog/2020/01/01/creating-your-first-aspnet-reporting-application/llms.txt)
- [Creating an ASP.NET Web Forms AJAX Application](https://www.textcontrol.com/blog/2020/01/01/creating-an-aspnet-web-forms-ajax-application/llms.txt)
- [Creating a WebSocket Server Project with Node.js](https://www.textcontrol.com/blog/2020/01/01/creating-a-websocket-server-project-with-nodejs/llms.txt)
- [Creating an Angular Document Editor Application](https://www.textcontrol.com/blog/2020/01/01/creating-an-angular-document-editor-application/llms.txt)
- [ReportingCloud .NET Core Quickstart Tutorial](https://www.textcontrol.com/blog/2019/07/24/reportingcloud-dotnet-core-quickstart-tutorial/llms.txt)
- [Document Permissions and Password Encryption](https://www.textcontrol.com/blog/2019/07/05/document-permissions-and-password-encryption/llms.txt)
- [New Online Sample: Build your First Report](https://www.textcontrol.com/blog/2019/07/03/build-your-first-report/llms.txt)
- [Create your First Document with ReportingCloud](https://www.textcontrol.com/blog/2019/02/19/create-your-first-document-with-reportingcloud/llms.txt)
- [MailMerge: Starting Each Merge Block on a New Page](https://www.textcontrol.com/blog/2016/09/09/mailmerge-starting-each-merge-block-on-a-new-page/llms.txt)
- [Windows Forms and WPF: End a List on Return when Line is Empty](https://www.textcontrol.com/blog/2016/08/26/windows-forms-and-wpf-end-a-list-on-return-when-line-is-empty/llms.txt)
