
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的绑定,可能会麻烦点,重新绑定一次数据源只取当前行的数据.
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)