请问MSFLEXGRID 控件显示出的数据表内容可以修改吗?急online

szsoft 2003-08-23 08:40:30
MSFLEXGRID 控件显示出的数据表内容可以修改吗?
我的意思是要修改所看到的单元格内容,由那个属性实现.
...全文
60 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Lucky527 2003-11-05
  • 打赏
  • 举报
回复
可以的
按上面的做一个文本框,配合网格完成修改功能,
再按下面的这段(已经实现)完成写回数据库,实现修改功能:
Private Sub Command1_Click() '修改表
Dim k As Integer
Dim j As Integer
On Error GoTo err
For k = 1 To Fg2.Rows - 1
Adodc1.Recordset.MoveFirst
Adodc1.Recordset.Move (k - 1)
For j = 2 To Fg2.Cols - 1
Adodc1.Recordset.Fields(j - 1).Value = Fg2.TextMatrix(k, j)
Adodc1.Recordset.Update
Next j
Next k
MsgBox "您成功的更新了数据库!"
err:
End Sub
注意当前表格和数据库中表的对应位置就好了
你试试看,我的能够成功运行
callzjy2 2003-11-01
  • 打赏
  • 举报
回复
Private Sub FillGrid()
Dim iRow As Integer
iRow = 1
With Grid1

While Not adoRstBasic.EOF
.AddItem ""
.TextMatrix(iRow, 0) = iRow
.TextMatrix(iRow, 1) = convertNull(adoRstBasic!Number)
.TextMatrix(iRow, 2) = convertNull(adoRstBasic!Name)
.TextMatrix(iRow, 3) = convertNull(adoRstBasic!Department)
.TextMatrix(iRow, 4) = convertNull(adoRstBasic!Headship)
.TextMatrix(iRow, 5) = convertNull(adoRstBasic!Postion)
.TextMatrix(iRow, 6) = convertNull(adoRstBasic!DutyState)
adoRstBasic.MoveNext
iRow = iRow + 1

Wend
End With
End Sub
cloud1002 2003-09-16
  • 打赏
  • 举报
回复
mark
chenkangli 2003-08-24
  • 打赏
  • 举报
回复
概述
MsFlexGrid 控件没有提供文本编辑的功能,下面的例子演示了如何利用一个TextBox 实现编辑当前网格的功能。

在按下一个键后, 就把TextBox 移动到当前的位置, 并激活。 在键入回车或移动到其他网格时, 就把TextBox 中的内容放到网格中。

实现步骤
1 打开 VB5, 开启一个新的工程。

2 在菜单“工程” 中选择 “部件”, 在列表中选中 “Microsoft FlexGrid Control ..”

3 放一个 MsFlexGrid 控件和一个TextBox 控件(Text1)到 Form1。 修改MsFlexGrid 控件的名称为 Grid1, 设置Grid1 的行,列 为 4, 固定行,列为 0。 设置 Text1 的 Visiable 为 False, BorderStyle 为 None(0)。

4 在Form1 的代码中增加声明:

Const ASC_ENTER = 13 '回车
Dim gRow As Integer
Dim gCol As Integer

5 增加代码到 Grid_KeyPress 过程:

Private Sub Grid1_KeyPress(KeyAscii As Integer)
' Move the text box to the current grid cell:
Text1.Top = Grid1.CellTop + Grid1.Top
Text1.Left = Grid1.CellLeft + Grid1.Left
' Save the position of the grids Row and Col for later:
gRow = Grid1.Row
gCol = Grid1.Col
' Make text box same size as current grid cell:
Text1.Width = Grid1.CellWidth - 2 * Screen.TwipsPerPixelX
Text1.Height = Grid1.CellHeight - 2 * Screen.TwipsPerPixelY
' Transfer the grid cell text:
Text1.Text = Grid1.Text
' Show the text box:
Text1.Visible = True
Text1.ZOrder 0 ' 把 Text1 放到最前面!
Text1.SetFocus
' Redirect this KeyPress event to the text box:
If KeyAscii <> ASC_ENTER Then
SendKeys Chr$(KeyAscii)
End If
End Sub

6 增加代码到 Text1_KeyPress 过程:

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = ASC_ENTER Then
Grid1.SetFocus ' Set focus back to grid, see Text_LostFocus.
KeyAscii = 0 ' Ignore this KeyPress.
End If
End Sub

7 增加代码到 Text1_LostFocus 过程:

Private Sub Text1_LostFocus()
Dim tmpRow As Integer
Dim tmpCol As Integer
' Save current settings of Grid Row and col. This is needed only if
' the focus is set somewhere else in the Grid.
tmpRow = Grid1.Row
tmpCol = Grid1.Col
' Set Row and Col back to what they were before Text1_LostFocus:
Grid1.Row = gRow
Grid1.Col = gCol
Grid1.Text = Text1.Text ' Transfer text back to grid.
Text1.SelStart = 0 ' Return caret to beginning.
Text1.Visible = False ' Disable text box.
' Return row and Col contents:
Grid1.Row = tmpRow
Grid1.Col = tmpCol
End Sub

8 好了。 按 F5 开始测试。 您可以自由地在 Grid 中移动, 按回车可以开始或结束编辑。
szsoft 2003-08-24
  • 打赏
  • 举报
回复
谢谢
结分
cuijiajian 2003-08-23
  • 打赏
  • 举报
回复
可以,不过要通过ADO控件,然后在加一个TEXT控件来做数据的修改用在MSFLEXGRID的CLICK那里编写控制TEXT控件的大小和移动,显示。在TEXT的CHANGE那里写数据的修改功能就OK啦!
hzybc 2003-08-23
  • 打赏
  • 举报
回复
用datagrid控件方便

或在记录集中修改,修改完再显示在MSFLEXGRID 控件中

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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