| 网站首页 | JAVA文章 | AppServers | Web开发 | 应用开发 | 资源下载 | 论坛
    想学好编程,学好外语很重要  [enadd  2006年12月25日]        
设为首页 加入收藏 联系站长
您现在的位置: 编程笔记网 >> 应用开发 >> VB.NET >> 报表处理 >> 文章正文
VB 使用 DataGrid 控件            【字体:
VB 使用 DataGrid 控件
作者:-    文章来源:-    点击数:    更新时间:2007-1-20

从 DataGrid 返回值
在 DataGrid 被连接到一个数据库后,可能想要监视用户单击了哪一个单元。您可以使用 RowColChange 事件 — 而不是 Click 事件 — 如下所示,:

Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
' 显示用户所单击的单元的文字、行和列的信息。
Debug.Print DataGrid1.Text; DataGrid1.Row; DataGrid1.Col
End Sub

使用 CellText 和 CellValue 方法
当一个列使用 NumberFormat 属性设置格式后,CellText 和 CellValue 属性是很有用的。NumberFormat 属性不必更改实际的数据的格式就可以更改任何包含数字的列的格式。例如,给定一个网格,其中包含一个名为 ProductID 的、包含整数的列。下面的代码将使 DataGrid 以"P-0000" 的格式来显示数据。换句话说,尽管在 ProductID 字段中所包含的实际数值为 "3",但该网格所显示的值将是 "P-0003"。

Private Sub Form_Load()
DataGrid1.Columns("ProductID").NumberFormat = "P-0000"
End Sub

要返回数据库中所包含的实际值,应使用 CellValue 方法,如下所示:

Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
Debug.Print _
DataGrid1.Columns("ProductID").CellValue(DataGrid1.Bookmark)
End Sub

注意 上面所用的 CellValue 和下面所用的 CellText 值,都需要将 bookmark 属性作为一个参数,功能才正确。

相反地,如果要返回该字段的格式化的值,应使用 CellText 方法:

Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
Debug.Print _
DataGrid1.Columns("ProductID").CellText(DataGrid1.Bookmark)
End Sub

注意 上面的 CellText 方法等价于使用 DataGrid 控件的 Texr 属性。

 

上一页  [1] [2] 

文章录入:enadd    责任编辑:enadd 
  • 上一篇文章:

  • 下一篇文章:
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    最新热点 最新推荐 相关文章
  • 慎用DataGrid的CurrentRowIn…

  • DataGrid 排序后确定DataSet…

  • DataGrid编程汇总

  •   网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    | 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明 | 管理登录 |