请教各位大师,我想修改数据,怎样使msflexgrid处于编辑状态

goldentree 2000-03-28 09:30:00
...全文
209 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
goldentree 2000-03-28
  • 打赏
  • 举报
回复
既然无现成的方法编辑msflexgrid,我使用了keypress方法可做到编辑meflexgrid,但不知如何将光标加进去
雨人吧 2000-03-28
  • 打赏
  • 举报
回复
可以与textbox,listbox or combobox 结合用很方便,msflexgrid总的来说比datagrid好使
sc74 2000-03-28
  • 打赏
  • 举报
回复
msflexgrid只能显示,不能编辑数据。能编辑数据的控件是:datagrid。但要将其allowupdate属性值设为true。并且其绑定数据源必须用客户端游标。
newsoft 2000-03-28
  • 打赏
  • 举报
回复
msflexgrid只能显示,好像是不能编辑数据的.
S391 2000-03-28
  • 打赏
  • 举报
回复
如果我记得没错的话,<<VB5程序员指南>>中有这样的例子.
具体做法是:
1.结合使用一个TextBox控件,将其设为无边框,Visible设为False;
2.当用户用鼠标点击一个MSFlexGrid单元格时,将TextBox移动到该单元格处(需计算位置),设置其长宽及内容,同时使它可视并获得焦点;
3.在TextBox中编辑内容,当TextBox失去焦点时,认为其编辑完毕,将内容回填到相应的单元格内,并使TextBox不可视;
4.如果需要使用其他控件,可如法炮制.
Un1 2000-03-28
  • 打赏
  • 举报
回复
如果你不想使用VSFlexGrid控件的话,只好写下面的程序了:

'Form1.frm 文件

VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 5355
ClientLeft = 1545
ClientTop = 1920
ClientWidth = 6420
LinkTopic = "Form1"
ScaleHeight = 5355
ScaleWidth = 6420
Begin VB.PictureBox Picture1
Height = 3495
Left = 1230
ScaleHeight = 3435
ScaleWidth = 3495
TabIndex = 0
Top = 990
Width = 3555
Begin VB.TextBox txtEdit
Height = 405
Left = 1260
TabIndex = 1
Top = 1440
Width = 1665
End
Begin MSFlexGridLib.MSFlexGrid mfgGrid
Height = 3585
Left = 0
TabIndex = 2
Top = 0
Width = 3795
_ExtentX = 6694
_ExtentY = 6324
_Version = 393216
Rows = 20
FixedRows = 0
FixedCols = 0
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

Private glngX As Long
Private glngY As Long


Private blnChanged As Boolean
Private blnInEdit As Boolean

Private lngRowHeight As Long



Private Sub TextSelectAll(Tb As TextBox)
With Tb
.SelStart = 0
.SelStart = 32767
End With
End Sub
Private Sub ShowErr()
MsgBox Err.Description, vbCritical
End Sub

Private Sub Form_Load()

With Screen
glngX = .TwipsPerPixelX
glngY = .TwipsPerPixelY
End With

With txtEdit
'.Visible = False

.Appearance = 0
.BorderStyle = vbBSNone

Dim l As Long
l = .hWnd

.Text = vbNullString
blnChanged = False
End With

With mfgGrid
SetParent l, .hWnd

.Appearance = flexFlat

.AllowBigSelection = False
.BackColorBkg = &H80000005

.BorderStyle = flexBorderNone

.FixedRows = 0
.FixedCols = 0
.FocusRect = flexFocusNone

lngRowHeight = .RowHeight(0)

End With

mfgGrid_EnterCell
End Sub



Private Sub MoveTextBox()
With mfgGrid
If .Rows > 0 Then
Dim lh As Long
lh = .RowHeight(0)

Dim lt As Long
lt = (.Row - .TopRow) * lh

If .Col = 0 Then
Dim ll As Long
ll = 0

Dim lw As Long
lw = .ColWidth(0)
Else
ll = .ColWidth(0)
lw = .ColWidth(1)
End If

txtEdit.Move ll, lt, lw - glngX, lh - glngY
End If
End With

End Sub

Private Sub mfgGrid_EnterCell()
On Error GoTo ErrorHandle
With mfgGrid
txtEdit = .Text
blnChanged = False
MoveTextBox
End With
Exit Sub

ErrorHandle:
ShowErr
End Sub

Private Sub mfgGrid_KeyPress(KeyAscii As Integer)

On Error GoTo ErrorHandle

With mfgGrid
Dim l As Long
l = .Row
If l >= 0 Then
Select Case KeyAscii
Case 0 To &H1F
Case Else

Dim s As String
s = .Text

blnInEdit = True

With txtEdit

If KeyAscii = vbKeySpace Then
.Text = s
blnChanged = False

TextSelectAll txtEdit

.SetFocus
Else
.Text = vbNullString
.SetFocus

SendKeys Chr$(KeyAscii), True
End If
End With
End Select
End If
End With
Exit Sub

ErrorHandle:
If Err <> 381 Then ShowErr
End Sub

Private Sub mfgGrid_LeaveCell()
On Error GoTo ErrorHandle
txtEdit_LostFocus
Exit Sub

ErrorHandle:
ShowErr
End Sub


Private Sub mfgGrid_Scroll()
On Error GoTo ErrorHandle
MoveTextBox
Exit Sub

ErrorHandle:
ShowErr
End Sub

Private Sub txtEdit_Change()
blnChanged = True
End Sub

Private Sub txtEdit_Click()
If Not blnInEdit Then
On Error GoTo ErrorHandle
mfgGrid_KeyPress vbKeySpace
End If
Exit Sub

ErrorHandle:
ShowErr
End Sub


Private Sub txtEdit_KeyPress(KeyAscii As Integer)
On Error GoTo ErrorHandle
Select Case KeyAscii
Case vbKeyEscape
txtEdit = mfgGrid.Text
blnChanged = False
GoTo SetFocusToGrid
Case vbKeyReturn

SetFocusToGrid:
KeyAscii = 0
mfgGrid.SetFocus
End Select
Exit Sub

ErrorHandle:
ShowErr
End Sub


Private Sub txtEdit_LostFocus()
blnInEdit = False

On Error GoTo ErrorHandle

If blnChanged Then
With txtEdit
If .Visible Then
.SelStart = 0

Dim s As String
mfgGrid.Text = .Text
End If
End With
blnChanged = False
End If
Exit Sub

ErrorHandle:
txtEdit = mfgGrid.Text
blnChanged = False
ShowErr
End Sub


7,762

社区成员

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

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