• datagridview控件


    1、datagridview控件具有多种不同类型的列

    说明

    DataGridViewTextBoxColumn

    与基于文本的值一起使用,在绑定到数字和字符串类型的值时自动生成

    DataGridViewCheckBoxColumn

    booleancheckState值一起使用,在绑定到这些类型的值时自动生成

    DataGridViewImageColumn

    用于显示图像,在绑定到字节数组、Image对象或Icon对象自动生成

    DataGridViewButtonColumn

    用于在单元格中显示按钮,不会在绑定时自动生成,通常用来做未绑定列

    DataGridViewComboBoxColumn

    用户在单元格中显示下拉列表,不会在绑定时自动生成,通常收到进行数据绑定

    DataGridViewLinkColumn

    用于在单元格中显示超链接,不会在绑定时自动生成,通常需要进行手动绑定数据

    2、例子

     1  '创建一个显示textBox的列()  
     2  Dim col1 As DataGridViewTextBoxColumn =New DataGridViewTextBoxColumn()  
     3  col1.Name = "Name"  
     4 col1.HeaderText = "姓名" '设置标题中显示的文本  
     5   
     6 Dim col3 As DataGridViewTextBoxColumn = NewDataGridViewTextBoxColumn()  
     7  col3.Name = "sex"  
     8 col3.HeaderText = "性别"  
     9   
    10 '将新建的列添加到控件中  
    11  DataGridView1.Columns.Add(col1)  
    12  DataGridView1.Columns.Add(col3)  
    13   
    14  '添加行  
    15  '创建新行   
    16  Dim row As DataGridViewRow = NewDataGridViewRow()  
    17  row.CreateCells(DataGridView1)  
    18  '设置单元格的值  
    19 row.Cells(0).Value = "张三"  
    20 row.Cells(1).Value = ""  
    21  DataGridView1.Rows.Add(row)  
    22  '添加第二行  
    23 dim row1 As String() = {"李四", ""}  
    24  DataGridView1.Rows.Add(row1)  

    3、绑定数据的方式

    1)绑定datatable
    DataTable dt=new DataTable();
    this.dataGridView1.DataSource=dt;
    2)绑定dataset
    DataSet ds=new DataSet ();
    this.dataGridView1.DataSource = ds;
    this.dataGridView1.DataMember = "表名";

     3)绑定arraylist,这个类都不太用了,被List<T>代替了

    ArrayList Al = new ArrayList();
    this.dataGridView1.DataSource = Al;
    4)绑定dictionary
    Dictionary<string, string> dic = new Dictionary<string, string>(); 
    this.dataGridView1.DataSource = dic;
    4)绑定List<T>
    this.dataGridVi.DataSource = new BindingList<Object>(List<Object>);
     
  • 相关阅读:
    论登陆博客园的时候忘记了密码
    LNOI 2019 旁观记
    [bzoj3790] 神奇项链
    [POI2000] 病毒
    [HAOI2008] 移动玩具
    [codevs1288] 埃及分数
    [hdu1401] Solitaire
    [洛谷P3806] [模板] 点分治1
    [国家集训队] 聪聪可可
    [洛谷P4178] Tree
  • 原文地址:https://www.cnblogs.com/crhdyl/p/6580298.html
Copyright © 2020-2023  润新知