--- title: "How to: Manipulate Columns and Rows by Using ColumnDefinitionsCollections and RowDefinitionsCollections" ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" helpviewer_keywords: - "controls [WPF], Grid class" - "Grid control [WPF], ColumnDefinitionCollection class" - "Grid control [WPF], RowDefinitionCollection class" ms.assetid: bfc7160a-45f2-4e17-9961-df414dfb13c5 --- # How to: Manipulate Columns and Rows by Using ColumnDefinitionsCollections and RowDefinitionsCollections This example shows how to use the methods in the and classes to perform actions like adding, clearing, or counting the contents of rows or columns. For example, you can , , or the items that are included in a or . ## Example The following example creates a element with a of `grid1`. The contains a that holds elements, each controlled by a different collection method. When you click a , it activates a method call in the code-behind file. :::code language="xaml" source="snippets/manipulate-columns-and-rows-by-using-columndefinitionscollections/csharp/Window1.xaml" id="Snippet1"::: This example defines a series of custom methods, each corresponding to a event in the [!INCLUDE[TLA#tla_xaml](../../../includes/tlasharptla-xaml-md.md)] file. You can change the number of columns and rows in the in several ways, which includes adding or removing rows and columns; and counting the total number of rows and columns. To prevent and exceptions, you can use the error-checking functionality that the method provides. :::code language="csharp" source="snippets/manipulate-columns-and-rows-by-using-columndefinitionscollections/csharp/Window1.xaml.cs" id="Snippet2"::: :::code language="vb" source="snippets/manipulate-columns-and-rows-by-using-columndefinitionscollections/vb/Window1.xaml.vb" id="Snippet2"::: ## See also - - -