Set control to specific row and column in code : Grid Operations « Windows Presentation Foundation « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » Windows Presentation Foundation » Grid Operations 
24.45.19.Set control to specific row and column in code
<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="" Height="300" Width="300"
    >
</Window>


//File:Window.xaml.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;


namespace WpfApplication1
{
    public partial class Window1 : System.Windows.Window
    {

        public Window1()
        {
            InitializeComponent();
            Grid g = new Grid();
            RowDefinition r = new RowDefinition();
            r.Height = new GridLength(0, GridUnitType.Auto);
            g.RowDefinitions.Add(r);
            r = new RowDefinition();
            r.Height = new GridLength(2, GridUnitType.Star);
            g.RowDefinitions.Add(r);
            r = new RowDefinition();
            r.Height = new GridLength(1, GridUnitType.Star);
            g.RowDefinitions.Add(r);

            ColumnDefinition c = new ColumnDefinition();
            c.Width = new GridLength(0, GridUnitType.Auto);
            g.ColumnDefinitions.Add(c);
            c = new ColumnDefinition();
            g.ColumnDefinitions.Add(c);

            TextBlock tb = new TextBlock();
            tb.Text = "Protocol:";
            Grid.SetColumn(tb, 0);
            Grid.SetRow(tb, 0);
            g.Children.Add(tb);

            tb = new TextBlock();
            tb.Text = "HyperText Transfer Protocol:";
            Grid.SetColumn(tb, 1);
            Grid.SetRow(tb, 0);
            g.Children.Add(tb);

            tb = new TextBlock();
            tb.Text = "Type:";
            Grid.SetColumn(tb, 0);
            Grid.SetRow(tb, 1);
            g.Children.Add(tb);

            tb = new TextBlock();
            tb.Text = "HTML Document";
            Grid.SetColumn(tb, 1);
            Grid.SetRow(tb, 1);
            g.Children.Add(tb);

            tb = new TextBlock();
            tb.Text = "Connection:";
            Grid.SetColumn(tb, 0);
            Grid.SetRow(tb, 2);
            g.Children.Add(tb);

            tb = new TextBlock();
            tb.Text = "Not encrypted";
            Grid.SetColumn(tb, 1);
            Grid.SetRow(tb, 2);
            g.Children.Add(tb);

            g.ShowGridLines = true;
            this.Content = g;
        }

    }
}
WPF Set Control To Specific Row And Column In Code
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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.