帮帮我!!

YY_yang1980 2006-12-27 03:39:30
如何在一个表里增加一个字段,并且在DataGridView中显示出来
...全文
84 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
YY_yang1980 2006-12-28
  • 打赏
  • 举报
回复
谢谢你,我给你加分.
snowfox007 2006-12-27
  • 打赏
  • 举报
回复
受用了
水如烟 2006-12-27
  • 打赏
  • 举报
回复
Public Class Form1

Dim table As DataTable

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
table = Sample.CreateTable
Me.DataGridView1.DataSource = table
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
With table.Columns.Add("序号", GetType(Integer))
.AutoIncrement = True
End With

For i As Integer = 0 To table.Rows.Count - 1
table.Rows(i).Item("序号") = i
Next

table.Columns("序号").ReadOnly = True
End Sub

End Class


Public Class Sample
Public Shared Function CreateTable() As DataTable
Dim table As New DataTable
With table
With .Columns
.Add("姓名")
.Add("年龄", GetType(Integer))
End With

.LoadDataRow(New Object() {"张三", 20}, True)
.LoadDataRow(New Object() {"李四", 21}, True)
.LoadDataRow(New Object() {"王五", 20}, True)
End With

Return table
End Function

End Class

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧