---
title: "Saving data from multiple tabs in a tab control"  
description: "Saving data from multiple tabs in a tab control"  
author: "Anonymous User"  
published: 2013-09-23  
updated: 2013-09-23  
canonical: https://www.mindstick.com/forum/1484/saving-data-from-multiple-tabs-in-a-tab-control  
category: "wpf"  
tags: ["wpf"]  
reading_time: 2 minutes  

---

# Saving data from multiple tabs in a tab control

I've been tasked with making a few changes to an existing program.

One of those changes is implementing a 'save' button. When clicked, it will iterate through each tab and save the contents to a [database](https://www.mindstick.com/articles/12226/use-of-database-in-sencha-extjs-and-insert-record-from-user-form-using-ajax), but I can't [figure](https://yourviews.mindstick.com/view/87536/what-are-ghosts-jobs-and-how-to-figure-out-them) out how to [access the data](https://answers.mindstick.com/qa/40056/what-is-the-weo-update-and-how-can-i-access-the-data) properly.

The tabs being added are separate [views](https://www.mindstick.com/forum/12838/compile-views-in-asp-dot-net-mvc), each with their own [viewmodel](https://www.mindstick.com/forum/157215/what-is-viewmodel-in-mvc) - the main view containing the tabcontrol also has its own viewmodel.

How would I go about accessing the tabcontrol, iterating through each tab and [saving](https://www.mindstick.com/blog/11865/guide-to-saving-15-for-retirement) the data in an orderly [fashion](https://www.mindstick.com/articles/188384/ladies-fashion-court-shoes-to-look-stylish-elegant)? (At this point I'm not sure if it's [relevant](https://yourviews.mindstick.com/view/20439/big-data-issues-and-challenges-relevant-to-characteristics-of-big-data) to show any code, but please do [request](https://www.mindstick.com/blog/255/post-get-and-request-function-in-php) whatever you'd need)

## Replies

### Reply by Sumit Kesarwani

Hi John,

Assuming, that every tab supports changes saving, create a view model, that will be on top of tab view models:

```
// this is the base class for tab view modelspublic class DocumentViewModel{    public void SaveChanges() {}}// this is the view model for tab containerpublic class EditorViewModel{    private SaveChanges()    {        foreach (var document in OpenedDocuments)        {           
document.SaveChanges();        }            }    public EditorViewModel()    {        SaveCommand = new RelayCommand(SaveChanges);    }    // this is your tabs    public ObservableCollection<DocumentViewModel> OpenedDocuments { get; private
set; }    public ICommand SaveChangesCommand { get; private set; }}
```


---

Original Source: https://www.mindstick.com/forum/1484/saving-data-from-multiple-tabs-in-a-tab-control

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
