dataGridView1添加的行数 运行的时候为什么不能直接显示出来?

dataGridView1添加的行数 运行的时候为什么不能直接显示出来?,第1张

把下面的代码放到Form_Load事件中,运行的时候就会显示了:

int index=this.dataGridView1.Rows.Add()

this.dataGridView1.Rows[index].Cells[0].Value = "1"

this.dataGridView1.Rows[index].Cells[1].Value = "2"

this.dataGridView1.Rows[index].Cells[2].Value = "3"

……

默认是可以添加行并编辑单元格的

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        Me.ResizeRedraw = True

        Dim ff As New DataGridView

        ff.ReadOnly = False‘在这里设置是否可编辑单元格

        ff.Parent = Me

ff.AllowUserToAddRows = True'这里设置是否显示添加新行

ff.Columns.Add("aa", "啊啊")

    End Sub

dataGridView的数据源是DataTable,DataTable有主键的话好处理.

假设dataGridView.DataSource=this.dtdt的col1列主键

显示当前行

this.dt.DefaultView.RowFilter = "col1=" + dataGridView1.CurrentRow.Cells["col1"].Value.ToString()

显示所有行

this.dt.DefaultView.RowFilter = string.Empty

如果是自定义的List的绑定,可能会麻烦点,重新绑定一次数据源只取当前行的数据.


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11772390.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-18
下一篇2023-05-18

发表评论

登录后才能评论

评论列表(0条)

    保存