MSHFlexGrid的问题。知道的请帮帮忙!!

cat7035 2002-01-25 03:32:41
我要做一个柜员管理的小系统。数据库如下:

柜员号 柜员密码 柜员姓名 柜员状态 柜员级别
1 123 张三 签到 管理员
2 456 李四 签退 操作员

。。。 。。。 。。 。。。 。。。


窗体上有个MSHFlexGrid1,就绑定到上面的表中,调用窗体时表中的记录全部显示到MSHFlexGrid1中,MSHFlexGrid1旁有两个按钮,添加和删除,用来实现向表中添加和删除记录。窗体上有5个文本框,运行时在这5个文本框中分别填入要添加的
柜员号 柜员密码 柜员姓名 柜员状态 柜员级别

代码如下:
Private Sub cmdadd_Click()
Dim entry ' Declare variables.
entry = "" & Chr(9) & Text1.Text & Chr(9) & Text2.Text & Chr(9) & Text3.Text & Chr(9) & Combo2.Text & Chr(9) & Combo1.Text ' Create entry.
MSHFlexGrid1.AddItem entry ' Add entry.
MSHFlexGrid1.Refresh
End Sub

Private Sub cmddelete_Click()
Dim i As Integer
i = MSHFlexGrid1.Row
MSHFlexGrid1.RemoveItem i
MSHFlexGrid1.Refresh
End Sub

运行时单独点添加、删除都没问题,但是进行过删除操作后,再点添加,就添加不上去(表里没有我添加的记录),但是多点几次就能添加上去了,就是说只添加一次不行,要多点几次才能添进去。

请问各位高手,为什么会这样??
...全文
108 点赞 收藏 14
写回复
14 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
jett 2002-01-26
原来这是MS的bug,去下个补丁吧

FIX: Changes to MSHFlexgrid Adding/Removing Records Not Visible
ID: Q223083



--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Visual Basic Professional and Enterprise Editions for Windows, version 6.0

--------------------------------------------------------------------------------


SYMPTOMS
After using the Remove method of the MSHFlexGrid, rows added with the AddItem method may not be visible.



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.

This bug was corrected in Visual Studio 6.0 Service Pack 3. For more information about Visual Studio service packs, please see the following articles in the Microsoft Knowledge Base:



Q194022 INFO: Visual Studio 6.0 Service Packs, What, Where, Why

Q194295 HOWTO: Tell That Visual Studio 6.0 Service Packs Are Installed



MORE INFORMATION

Steps to Reproduce Behavior
Create a new standard Visual Basic project. Form1 is create by default.


Add the MSHFlexGrid to the Visual Basic toolbox.


Place an MSHFlexGrid and two CommandButtons on the form.


Add the following code to your application:



Private Sub Command1_Click()
MSHFlexGrid1.AddItem "Hello"
End Sub

Private Sub Command2_Click()
MSHFlexGrid1.RemoveItem MSHFlexGrid1.Rows - 1
End Sub

Private Sub Form_Load()
Command1.Caption = "AddItem"
Command2.Caption = "RemoveItem"
End Sub


Run the project


Click the "Command1" button three times to add three rows.


Click the "Command2" button three times to remove the three rows.


Click the "Command1" button three times again to add back the three rows.


If you're using the MSHFlexGrid prior to the version that shipped with Visual Basic 6.0 Service Pack 3, you won't see the second batch of rows created by clicking the AddItem button.

With the version of MSHFlexGrid that shipped with Visual Basic 6.0 Service Pack 3, this problem does not occur.
回复
_西瓜皮_ 2002-01-25
在MSHFlexGrid1.AddItem entry 后加个序号,看看有什么反映。
回复
MarGo 2002-01-25
Adodc1.Refresh
然后把记录集绑定到MSHFlexGrid1上
我建议你不要用MSHFlexGrid,用LISTVIEW
给你个例子:With LISTVIEW1.ListItems
.Add , "WW" & rs!dwid, RS!dwdm
.Item("WW" & rs!dwid).SubItems(1) = rstrs!dwmc
.Item("WW" & rs!dwid).SubItems(2) = rstrs!kmbm
.Item("WW" & rs!dwid).SubItems(3) = rstrs!khhmc

End With
删除则在LISTVIEW的
Private Sub Cmddel_Click()
Dim LR As Long
LR = MsgBox("您确定要删除该单位信息吗?", vbInformation + vbOKCancel, "提示信息")
If LR = vbOK Then

LISTVIEW1.ListItems.Remove LISTVIEW1.SelectedItem.Index
'"xx" + Trim(Str(m_intid))
LISTVIEW1.Refresh
txtdwbm.Text = ""
txtdwmc.Text = ""
Cmddel.Enabled = False
End If

End Sub
回复
cat7035 2002-01-25
wjying(葡萄):怎么动游标?动到哪?
文本框的内容加到表里,而且都加到表的最后一行,这和游标有什么关系呀?
回复
jett 2002-01-25
删除的时候最好动一下游标
否则游标会指这被删除的记录
回复
cat7035 2002-01-25
MSHFlexGrid1.Refresh
DataEnvironment1.rsCommand1.Requery
我都用了,还是不行,我总是觉得添加只是把文本框的内容加到表里,是不是和焦点在哪,鼠标在哪都没有关系?
回复
cat7035 2002-01-25
dbcontrols(泰山__帮助你使我感到快乐.):还是不行,点了两次添加才添进去。我就奇怪为什么一次就不行?如果不进行删除操作,那添加按忸就没问题,只要删除过一次,再想添加就得多点几次。删除和添加有什么冲突吗??

回复
cat7035 2002-01-25
还是不行,点了两次添加才添进去。我就奇怪为什么一次就不行?如果不进行删除操作,那添加按忸就没问题,只要删除过一次,再想添加就得多点几次。删除和添加有什么冲突吗??
回复
zhangzzc 2002-01-25
如果不分组,尽量不要用MSHFlexGrid控件,用MSFlexGrid控件就可以了,用MSHFlexGrid控件总是出现莫名其妙的问题
如果有不同见解可与我联系:qq-120807015
回复
lichard 2002-01-25
是不是refresh一下就好了/
回复
dbcontrols 2002-01-25
DataEnvironment1.rsCommand1.Requery
回复
cat7035 2002-01-25
楼上的,谢了!
不过我用的不是ADODC控件,是数据环境!
我觉得添加记录只是把我填如文本框的各项加入表中,这和数据环境有关系吗?
回复
lily0000000 2002-01-25
adodc1.recordset.update
回复
dbcontrols 2002-01-25
Adodc1.Refresh
回复
相关推荐
发帖
VB基础类
创建于2007-09-28

7489

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2002-01-25 03:32
社区公告
暂无公告