The current number of Columns : Grid Operations « Windows Presentation Foundation « C# / CSharp Tutorial






<Window  
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="WpfApplication1.Window1"
    Title="ColumnDefinitions Sample">
    <Border BorderBrush="Black" Background="White" BorderThickness="2">
  <DockPanel Margin="10,0,0,0">
    <TextBlock FontSize="20" FontWeight="Bold" DockPanel.Dock="Top">Grid Column and Row Collections</TextBlock>
        <Grid DockPanel.Dock="Top" HorizontalAlignment="Left" Name="grid1" ShowGridLines="true" Width="625" Height="400">
          <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
            <ColumnDefinition/>
          </Grid.ColumnDefinitions>
          <Grid.RowDefinitions>
          <RowDefinition/>
            <RowDefinition/>
            <RowDefinition/>
          </Grid.RowDefinitions>
        </Grid>

        <StackPanel HorizontalAlignment="Left" Orientation="Horizontal" Width="625" DockPanel.Dock="Top">
            <Button Width="125" Click="colCount">How Many Columns?</Button>
        </StackPanel>    

  </DockPanel>
  </Border>  
</Window>

//File:Window.xaml.cs

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;

namespace WpfApplication1
{
    public partial class Window1 : Window
    {
        RowDefinition rowDef1;
        ColumnDefinition colDef1;


        private void colCount(object sender, RoutedEventArgs e)
        {
            Console.WriteLine("The current number of Columns is: " + grid1.ColumnDefinitions.Count);
        }
    }
}
WPF The Current Number Of Columns








24.45.Grid Operations
24.45.1.Set Row Height and column Width for GridSet Row Height and column Width for Grid
24.45.2.Set Row and Column Index when Adding Buttons to GridSet Row and Column Index when Adding Buttons to Grid
24.45.3.Clear All ColumnsClear All Columns
24.45.4.Clear All RowsClear All Rows
24.45.5.Remove One ColumnRemove One Column
24.45.6.Remove One RowRemove One Row
24.45.7.The current number of ColumnsThe current number of Columns
24.45.8.The current number of RowsThe current number of Rows
24.45.9.Remove 5 Columns with ColumnDefinitions.RemoveRangeRemove 5 Columns with ColumnDefinitions.RemoveRange
24.45.10.Remove 5 Row with RowDefinitions.RemoveRangeRemove 5 Row with RowDefinitions.RemoveRange
24.45.11.Contains RowContains Row
24.45.12.Contains Column?Contains Column?
24.45.13.Insert RowInsert Row
24.45.14.Insert ColumnInsert Column
24.45.15.Is Grid ReadOnlyIs Grid ReadOnly
24.45.16.Add a ColumnDefinition to GridAdd a ColumnDefinition to Grid
24.45.17.Add a RowDefinition to GridAdd a RowDefinition to Grid
24.45.18.Setting Grid row heights in codeSetting Grid row heights in code
24.45.19.Set control to specific row and column in codeSet control to specific row and column in code
24.45.20.Show Grid lines in codeShow Grid lines in code
24.45.21.Programmatically use the positioning methods of GridProgrammatically use the positioning methods of Grid