Mega Code Archive

 
Categories / VB.Net Tutorial / WPF
 

Insert Column

<Window       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     x:Class="columndefinitions_grid.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/>           </Grid.ColumnDefinitions>           <Grid.RowDefinitions>           <RowDefinition/>             <RowDefinition/>           </Grid.RowDefinitions>         </Grid>         <StackPanel HorizontalAlignment="Left" Orientation="Horizontal" Width="625" DockPanel.Dock="Top">             <Button Width="125" Click="insertColAt">Insert Column</Button>         </StackPanel>       </DockPanel>   </Border>   </Window> //File:Window.xaml.vb Imports System Imports System.Windows Imports System.Windows.Controls Imports System.Windows.Documents Namespace columndefinitions_grid   Public Partial Class Window1     Inherits Window     Private rowDef1 As RowDefinition     Private colDef1 As ColumnDefinition     Private Sub insertColAt(sender As Object, e As RoutedEventArgs)       colDef1 = New ColumnDefinition()       grid1.ColumnDefinitions.Insert(grid1.ColumnDefinitions.Count, colDef1)       Console.WriteLine(grid1.ColumnDefinitions.IndexOf(colDef1).ToString())     End Sub   End Class End Namespace