vb.net在页面加载时创建空列datagridview

时间:2014-11-08 03:13:23

标签: vb.net datagridview

您好我想在page_load个事件

上的datagridview上定义一个列

我如何实现这一目标?

我已尝试过以下代码

    dgv_beli.AutoGenerateColumns = False
    dgv_beli.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None

    dgv_beli.SelectionMode = DataGridViewSelectionMode.FullRowSelect


    'DEFINE COLUMN MANUALLY
    'kode barang
    Dim colKode As New DataGridViewTextBoxColumn
    colKode.HeaderText = "Kode"
    colKode.Name = "Kode"

    'nama barang
    Dim colNama As New DataGridViewTextBoxColumn
    colNama.HeaderText = "Nama"
    colNama.Name = "Nama"

    'jenis
    Dim colJenis As New DataGridViewTextBoxColumn
    colJenis.HeaderText = "Jenis"
    colJenis.Name = "kd_jenis"
    colJenis.Width = 120

    dgv_beli.AllowUserToAddRows = True
    dgv_beli.Columns.Add(colKode)
    colKode.ReadOnly = True
    dgv_beli.Columns.Add(colNama)
    colNama.ReadOnly = True
    dgv_beli.Columns.Add(colJenis)
    colJenis.ReadOnly = True
    dgv_beli.Sort(dgv_beli.Columns(0), System.ComponentModel.ListSortDirection.Ascending)
    dgv_beli.Rows.Add(colKode, colNama, colJenis)

但是datagridview stll为空

请帮助我解决这个问题..谢谢

0 个答案:

没有答案