关于msflexgrid的问题

hjm1980_2005 2008-01-23 06:07:22
主窗体上有一个msflexgrid控件,点击一个按钮,会弹出另一个窗体来,这个窗体上也有一个msflexgrid,我通过双击这个msflexgrid控件,把数据添加到主窗体上的msflexgrid,然后我在主窗体上点保存这些添加的数据时候,主窗体上的msflexgrid的数据就消失了,真是怪了,真的很急呀,请各位大哥帮忙呀!
...全文
100 点赞 收藏 14
写回复
14 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
Phenlit 2008-01-29
窗体可以传值的,除非你的窗口中用private声明

你上面的错误,主要是每次写数据之前就清掉了数据了,所以没数据写进去,也显示不了数据

我在9楼已经说了,你把
.Rows=i
注释掉,就可以用了,你去试试啊,有什么问题再反映上来
回复
hjm1980_2005 2008-01-29
保存的時候msflexgrid的值才會自動消失
回复
hjm1980_2005 2008-01-29
我的主要用是窗体之間傳值,通過窗体傳值給msflexgrid,是不是這樣不行呀
回复
hjm1980_2005 2008-01-28
那怎麽辦呢?有好的解決辦法嗎
回复
yangao 2008-01-28
Private   Sub   Msflexdata_save() 
Dim i As Integer
Dim rs As ADODB.Recordset
Dim con As ADODB.Connection
Set con = New ADODB.Connection
con.Open strConnect_String
Set rs = New ADODB.Recordset
rs.Open "select * from tb_tihuodetail", con, adOpenKeyset, adLockOptimistic
rs.AddNew
With MSFlexGrid1
For i = 1 To .Rows -1
'.Rows = i
.Row = i
.Col = 0
txtname.Text = .Text
rs!ck_orderno = .Text
.Col = 1
rs!ck_name = .Text
.Col = 2
rs!ck_description = .Text
.Col = 3
rs!ck_num = .Text
.Col = 4
rs!ck_unit = .Text
.Col = 5
rs!ck_price = .Text
rs!tihuonum = txtorderno.Text
rs.Update
Next i
End With
End Sub


试试
回复
Phenlit 2008-01-25
哈哈,问题就在人的代码中,请看
With MSFlexGrid1
For i = 1 To .Rows
.Rows = i
.Row = .Row
.Col = 0
txtname.Text = .Text
rs!ck_orderno = .Text
.Col = 1
rs!ck_name = .Text
.Col = 2
rs!ck_description = .Text
.Col = 3
rs!ck_num = .Text
.Col = 4
rs!ck_unit = .Text
.Col = 5
rs!ck_price = .Text
rs!tihuonum = txtorderno.Text
rs.Update
Next i
End With

第一次循环都会改变总行数,数据也跟着改变了,肯定保存不了数据,并且会重绘
回复
qq5181688 2008-01-25
你的MSFlexGrid用的什么方式显示数据的!用的代码还是绑定!应该用的绑定了.
你把保存用的这些代码去掉,结果还是一样的:
rs.AddNew
With MSFlexGrid1
For i = 1 To .Rows
.Rows = i
.Row = .Row
.Col = 0
txtname.Text = .Text
rs!ck_orderno = .Text
.Col = 1
rs!ck_name = .Text
.Col = 2
rs!ck_description = .Text
.Col = 3
rs!ck_num = .Text
.Col = 4
rs!ck_unit = .Text
.Col = 5
rs!ck_price = .Text
rs!tihuonum = txtorderno.Text
rs.Update
Next i
End With
建议改用非绑定显示数据!
回复
yangao 2008-01-24

主要是贴主窗体的代码
回复
hjm1980_2005 2008-01-24
这些是子窗体的代码初始化:
connect_string_init
Set Con = New ADODB.Connection
Con.Open strConnect_String
Set Rs = New ADODB.Recordset
Rs.Open "select * from tb_kcxx", Con, adOpenKeyset, adLockOptimistic
把数据添加到主窗体数据时的代码:
Private Sub MSFlexGrid1_DblClick()
Static i As Integer
With MSFlexGrid1
If .Row < 1 Or .Row > .Rows Then
Exit Sub
End If
.Row = .Row
.Col = 0
objdata.objid = .Text
.Col = 1
objdata.objname = .Text
.Col = 2
objdata.objsize = .Text
.Col = 3
objdata.objnum = .Text
.Col = 4
objdata.objunit = .Text
.Col = 5
objdata.objprice = .Text
End With
i = i + 1
frmtihuodan.MSFlexGrid1.Rows = i
With frmtihuodan.MSFlexGrid1
.Rows = .Rows + 1
.TextMatrix(.Rows - 1, 0) = objdata.objid
.TextMatrix(.Rows - 1, 1) = objdata.objname
.TextMatrix(.Rows - 1, 2) = objdata.objsize
.TextMatrix(.Rows - 1, 3) = objdata.objnum
.TextMatrix(.Rows - 1, 4) = objdata.objunit
.TextMatrix(.Rows - 1, 5) = objdata.objprice
End With
frmitemdata.Hide
End Sub
你们看看,我感觉代码是没有问题的
回复
hjm1980_2005 2008-01-24
不是呀
回复
rexyudl 2008-01-24
首先支持楼上的观点,你的程序有问题了!另外问一个问题
你用的是不是ADODC啊?
回复
yangao 2008-01-24
应该是你代码写的有问题

把代码贴出来看看
回复
hjm1980_2005 2008-01-24
這些沒有問題,主窗体的保存代碼:
Private Sub Msflexdata_save()
Dim i As Integer
Dim rs As ADODB.Recordset
Dim con As ADODB.Connection
Set con = New ADODB.Connection
con.Open strConnect_String
Set rs = New ADODB.Recordset
rs.Open "select * from tb_tihuodetail", con, adOpenKeyset, adLockOptimistic
rs.AddNew
With MSFlexGrid1
For i = 1 To .Rows
.Rows = i
.Row = .Row
.Col = 0
txtname.Text = .Text
rs!ck_orderno = .Text
.Col = 1
rs!ck_name = .Text
.Col = 2
rs!ck_description = .Text
.Col = 3
rs!ck_num = .Text
.Col = 4
rs!ck_unit = .Text
.Col = 5
rs!ck_price = .Text
rs!tihuonum = txtorderno.Text
rs.Update
Next i
End With
End Sub
回复
bluefox1979 2008-01-24
检查保存过程.单步调试
回复
发动态
发帖子
VB基础类
创建于2007-09-28

7453

社区成员

VB 基础类
申请成为版主
社区公告
暂无公告