可以修改MSFLEXGRID显示的内容吗?如何做?online...

szsoft 2003-08-23 09:15:13
可以修改MSFLEXGRID显示的内容吗?如何做?
...全文
109 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
liul17 2003-08-25
  • 打赏
  • 举报
回复
如果是直接录入,也是可以的
msflexgrid1.additem "" '增加一空行
然后用粘文本框的方法即可实现
liul17 2003-08-25
  • 打赏
  • 举报
回复
可以,
dim rd as recordset
set rd = db.openrecordset(...)
do while not rd.eof

msflexgrid1.additem XX & vbtab & XX & vbtab & XX
rd.movenext
loop
planetike 2003-08-24
  • 打赏
  • 举报
回复
方法一:
mshflexgrid.TextMatrix(行,列)="内容"

方法二:
mshflexgrid.row=行
mshflexgrid.row=列
mshflexgrid.text="内容"
vbcool 2003-08-24
  • 打赏
  • 举报
回复
MSHFLEXGRID 名.row = 行
MSHFLEXGRID 名.COL = 列
MSHFLEXGRID 名.text = 新值
tanyx 2003-08-24
  • 打赏
  • 举报
回复
当然可以啊,grid1.texta... grid1.textma....两个属性,都可以。
szsoft 2003-08-24
  • 打赏
  • 举报
回复
chenkangli(小白)
thank you very much!!!
______
by the way, Can I add record in Msflexgrid ?
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
  • 打赏
  • 举报
回复
明白了,
结帖
tanhx 2003-08-24
  • 打赏
  • 举报
回复
Private Sub GetText(ByVal msfGrid As MSFlexGrid, ByVal txt As TextBox, ByVal bln As Boolean)
With msfGrid
If MSFGridCol >= 1 And txt.Text <> "" Then
.TextMatrix(MSFGridRow, MSFGridCol) = txt.Text
txt.Text = ""
txt.Visible = False
End If

If Not bln Then Exit Sub

txt.Move .Left + .CellLeft, .Top + .CellTop, .CellWidth, .CellHeight
txt.Visible = True
txt.SetFocus
txt.Text = .TextMatrix(.Row, .Col)
.TextMatrix(.Row, .Col) = ""
MSFGridRow = .Row
MSFGridCol = .Col
End With
End Sub
然后在msflexgrid的click或dbclick中调用。
szsoft 2003-08-24
  • 打赏
  • 举报
回复
grid1 是绑定了表的吧,
我现在的用MSFLEXGRID,并且显示的数据是按不同查询条件得到的.
yeah_yz 2003-08-24
  • 打赏
  • 举报
回复
在窗体上加一个文本框Text1,并设置它的visible属性为false,假定你的网格控件为Grid1
Sub Grid1_KeyPress(KeyAscii as integer)
Text1.text=text1.text & chr(KeyAscii)
Text1.SelStart=1
Text1.Move Grid1.CellLeft+Grid1.Left,_
Grid1.CellTop+Grid1.Top,_
Grid1.CellWidth,Grid1.CellHeight
Text1.Visible=True
Text1.SetFous
End Sub

Sub Grid1_LeaveCell()
If Text1.visible=False then
Exit sub
End if
Grid1.Text=Text1
Text1.Visible=False
Text1.Text=""
End sub


szsoft 2003-08-24
  • 打赏
  • 举报
回复
jsgzhanxiao(战箫)你好
你的思想我明白了,可我我是小鸟,能否给点代码/
战箫 2003-08-24
  • 打赏
  • 举报
回复
不好意思,我刚才说的不是你想要的意思。呵。
如果想直接在网格上修改,可以加一个text控件,然后让text控件跟着你的鼠标所点的网格走,就是你鼠标点到哪个格,就让text控件move到所对应的msflexgrid中的格上,并大小与格一致,用text的move方法就可以,然后将msflexgrid的格中的内容赋给text.text,然后你就可以修改text中的内容了,改完后可以用回车或是其他什么键的,(你自己定哦),将数据保存到数据库就OK了。
战箫 2003-08-24
  • 打赏
  • 举报
回复
你说的是要修改msflexgrid的内容还是所显示的数据库中的内容呢?
如果只是msflexgrid中的内容的话,planetike(阿胜) 说的非常详细了。
如果是改数据库中的内容的话,当然要用ado连接到数据库,改数据,或是ado对象及sql语句来修改了,如rs!字段=值,改完再将msflexgrid控件内容刷新一下就OK了。
szsoft 2003-08-24
  • 打赏
  • 举报
回复
我的意思是表格的内容用MSFLEXGRID显示出来后,直接网格中修改.救救我..
zhshop 2003-08-23
  • 打赏
  • 举报
回复
你所谓的修改显示的内容是什么意思?

1,451

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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