zoukankan      html  css  js  c++  java
  • C#后台动态添加Grid表格

    前面页面:

    1 <ScrollViewer x:Name="sv_data" Grid.Row="1" BorderBrush="#25A0DA" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
    2 
    3 <Grid x:Name="rgv_schedule" Background="White" Width="3150"></Grid>
    4 
    5 </ScrollViewer>
    View Code

    从后台动态添加行和列

    添加多行:

    1                 //新建5行
    2                 for (int k = 0; k < 5; k++)
    3                 {
    4                     RowDefinition row = new RowDefinition() { Height = new GridLength(30) };
    5                     grid_box.RowDefinitions.Add(row);
    6                 }
    View Code

    添加列:

     1             //清空列表
     2             rgv_schedule.Children.Clear();
     3             //添加第一行(表头)
     4             RowDefinition row = new RowDefinition() { Height = new GridLength(30) };
     5             rgv_schedule.RowDefinitions.Add(row);
     6             //姓名列
     7             ColumnDefinition col_name = new ColumnDefinition() { Width = new GridLength(50) };
     8             rgv_schedule.ColumnDefinitions.Add(col_name);
     9 
    10             System.Windows.Controls.Border b_name = new System.Windows.Controls.Border() { BorderThickness = new Thickness(1, 1, 1, 1), BorderBrush = new SolidColorBrush(System.Windows.Media.Colors.Black) };
    11             TextBlock txt_name = new TextBlock() { Text = "姓名", FontSize = 13, FontWeight = FontWeights.Black, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };
    12             b_name.Child = txt_name;
    13             b_name.SetValue(Grid.ColumnProperty, 0);//设置边框所在列
    14             b_name.SetValue(Grid.RowProperty, 0);//设置边框所在行
    15             rgv_schedule.Children.Add(b_name);//将边框添加到表格中
    View Code
  • 相关阅读:
    银行家算法实例(转)
    DNS中的七大资源记录介绍!(转)
    android之存储篇_SQLite数据库_让你彻底学会SQLite的使用(转)
    回顾HTML5的语义化元素
    vueJs2.0学习笔记(六)
    vueJs2.0学习笔记(五)
    vueJs的学习笔记(四)
    vueJs2.0学习笔记(三)
    vueJs的学习笔记(二)
    vueJs 2.0学习笔记(一)
  • 原文地址:https://www.cnblogs.com/KLLQBKY/p/7049867.html
Copyright © 2011-2022 走看看