拿这个问题没办法,知道的朋友帮帮忙,mshflexgrid的问题。在线等

pingpangqiuliuji 2004-11-30 11:39:12
问题描述:将ADO控件与mshflexgrid控件绑定后,mshflexgrid不能返回正确的当前选择的行(mshflexgrid.row)。
详细描述:
(1):登陆窗体的时候,我在form_load事件中将ado和mshflexgrid两个控件绑定,这个时候如果ado记录集不为空,mshflexgrid能返回正确的当前行,但是当我执行下面两个步骤的后,mshflexgrid就不能返回正确的当前行
(2)执行一次查询,ado控件的记录集为空
(3)再执行一次查询,ado控件的记录集不为空,鼠标点mshflexgrid控件,这个时候mshflexgrid返回的当前行(mshflexgrid.row)是个错误的当前行.如果记录集较多,点右边的下拉按钮后,再点mshflexgrid中的记录,返回的当前行又是正确
...全文
143 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
Abyss-Xu 2004-12-03
  • 打赏
  • 举报
回复
mshflexgrid 绑定到空集合。
你的问题我有遇到过,这是mshflexgrid控件本身的问题
你最好不要绑定到空集合,如果rs 为空的话,给 mshflexgrid 留行空行这样rs 不为空时绑定就没有问题了。

if adodc1.Recordset.RecordCount<1 then
mshflexgrid1.clear
mshflexgrid1.rows=2

'如果要标题的话这样
mshflexgrid1.textmatrix(0,0)="你要写的"
mshflexgrid1.textmatrix(0,1)="你要写的"
'....
else
绑定
end if

aohan 2004-12-02
  • 打赏
  • 举报
回复
pingpangqiuliuji(独孤求败)


我试了一下你的问题,我上面想法确实不行,不过还有个折中的办法,你可以试一下


在你的查询赋值之前,先

unload me '把窗体卸掉
load me '再装一次
set MSH.RecordSource =rs


这样就能正确返回MSH的 row 值了


我现在也没有发现更好的办法
aohan 2004-11-30
  • 打赏
  • 举报
回复
那就这样,你用
dim rs as new adodb.recordset

rs.open "" ‘你上面的语句

然后判断

if not rs.eof '判断不为空时再赋值
set MSH.RecordSource =rs
MSH.Refresh
end if


这样试试看是否也有问题
pingpangqiuliuji 2004-11-30
  • 打赏
  • 举报
回复
兄弟们:应该不是SQL语句的问题。我在查询分析器里执行了。我就是觉得奇怪的是,如果记录集没出现空的话,不会出现那问题。就是当查询出新空后,在去查询,就有那个问题。郁闷
pingpangqiuliuji 2004-11-30
  • 打赏
  • 举报
回复
还是不行。我的代码
这里是登陆:(form_load)
Adodc1.CursorLocation = adUseClient
Adodc1.CursorType = adOpenDynamic
Adodc1.LockType = adLockOptimistic
Adodc1.ConnectionString = strCnnstring

Adodc1.RecordSource = "select yw_infob.ywbh as 业务流水号,ryinfo.RYXM as 施工人员,yw_infob.ywzl as 业务种类,yw_infob.uname as 用户名称,yw_infob.uphone as 用户号码,yw_infob.qh as 区号,yw_infob.uaddr as 联系地址,yw_infob.ulxfs as 联系方式,bminfo.BMMC as 受理营业厅,yw_infob.ywslsj as 受理时间,sgry_infob.wgdjsj as 完工时间,yw_infob.sbtg as 设备,yw_infob.ZJtype as 装机类型,sgry_infob.dgmemo as 备注,sgry_infob.pgbh as 派工编号,sgry_infob.rybh as ' ','未完工' as wg from yw_infob,sgry_infob,(select rybh,RYXM from ryinfo where BMBH='" & Trim(Str_bmbh) & "' and XTBH='" & Trim(Str_xtcode) & "' ) as ryinfo,bminfo where bminfo.bmtype='JYB' and sgry_infob.wgzt='Y' and bminfo.bmbh='" & Trim(Str_bmbh) & "' and yw_infob.ywbh=sgry_infob.ywbh and sgry_infob.bmbh=bminfo.bmbh and sgry_infob.rybh=ryinfo.rybh and sgry_infob.wgdjsj > '" & DTP1.Value & "' and sgry_infob.wgdjsj < '" & DTP2.Value & "' union " & _
"select wg_infob.ywbh as 业务流水号,ryinfo.RYXM as 施工人员,wg_infob.ywzl as 业务种类,user_card.uname as 用户名称,user_card.uphone as 用户号码,user_card.qh as 区号,user_card.uaddr as 联系地址,user_card.ulxfs as 联系方式,bminfo.BMMC as 受理营业厅,wg_infob.ywslsj as 受理时间,wg_infob.wgsj as 完工时间,user_card.sbtg as 设备,user_card.ZJtype as 装机类型,sgry_infob.dgmemo as 备注,wg_infob.pgbh as 派工编号,sgry_infob.rybh as ' ','完工' as wg from user_card,sgry_infob,(select rybh,RYXM from ryinfo where BMBH='" & Trim(Str_bmbh) & "' and XTBH='" & Trim(Str_xtcode) & "' ) as ryinfo,bminfo,wg_infob where bminfo.bmbh='" & Trim(Str_bmbh) & "' and wg_infob.wgzt='Y' and bminfo.BMtype='JYB' and wg_infob.ywbh=sgry_infob.ywbh and wg_infob.uphone=user_card.uphone and sgry_infob.rybh=ryinfo.rybh and sgry_infob.bmbh=bminfo.bmbh and wg_infob.wgsj > '" & DTP1.Value & "' and wg_infob.wgsj < '" & DTP2.Value & "' order by ywslsj desc"
Set MSH.DataSource = Adodc1

下面是查询事件中的代码:
If Opt(0).Value = True Then '显示成功的完工业务
'判断是成功的公单还是不成功的公单
Str_query3 = "select wg_infob.ywbh as 业务流水号,ryinfo.RYXM as 施工人员,wg_infob.ywzl as 业务种类,user_card.uname as 用户名称,user_card.uphone as 用户号码,user_card.qh as 区号,user_card.uaddr as 联系地址,user_card.ulxfs as 联系方式,bminfo.BMMC as 受理营业厅,wg_infob.ywslsj as 受理时间,wg_infob.wgsj as 完工时间,user_card.sbtg as 设备,user_card.ZJtype as 装机类型,sgry_infob.dgmemo as 备注,wg_infob.pgbh as 派工编号,sgry_infob.rybh as ' ','完工' as wg from user_card,sgry_infob,(select rybh,RYXM from ryinfo where BMBH='" & Trim(Str_bmbh) & "' and XTBH='" & Trim(Str_xtcode) & "' ) as ryinfo,bminfo,wg_infob where wg_infob.wgzt='Y' and bminfo.BMtype='JYB' and wg_infob.ywbh=sgry_infob.ywbh and wg_infob.uphone=user_card.uphone and sgry_infob.rybh=ryinfo.rybh and sgry_infob.bmbh=bminfo.bmbh and bminfo.bmbh='" & Trim(Str_bmbh) & "'" & Str_query2 & " union " & _
" select yw_infob.ywbh as 业务流水号,ryinfo.RYXM as 施工人员,yw_infob.ywzl as 业务种类,yw_infob.uname as 用户名称,yw_infob.uphone as 用户号码,yw_infob.qh as 区号,yw_infob.uaddr as 联系地址,yw_infob.ulxfs as 联系方式,bminfo.BMMC as 受理营业厅,yw_infob.ywslsj as 受理时间,sgry_infob.wgdjsj as 完工时间,yw_infob.sbtg as 设备,yw_infob.ZJtype as 装机类型,sgry_infob.dgmemo as 备注,sgry_infob.pgbh as 派工编号,sgry_infob.rybh as ' ','未完工' as wg from yw_infob,sgry_infob,(select rybh,RYXM from ryinfo where BMBH='" & Trim(Str_bmbh) & "' and XTBH='" & Trim(Str_xtcode) & "' ) as ryinfo,bminfo where yw_infob.ywbh=sgry_infob.ywbh and sgry_infob.wgzt='Y' and sgry_infob.bmbh=bminfo.bmbh and bminfo.bmbh='" & Trim(Str_bmbh) & "' and bminfo.bmtype='JYB' and sgry_infob.rybh=ryinfo.rybh " & Str_query1 & " order by ywslsj desc"
Else
'Str_query3 = "select wg_infob.ywbh as 业务流水号,ryinfo.RYXM as 施工人员,wg_infob.ywzl as 业务种类,user_card.uname as 用户名称,user_card.uphone as 用户号码,user_card.qh as 区号,user_card.uaddr as 联系地址,user_card.ulxfs as 联系方式,bminfo.BMMC as 受理营业厅,wg_infob.ywslsj as 受理时间,wg_infob.wgsj as 完工时间,user_card.sbtg as 设备,user_card.ZJtype as 装机类型,sgry_infob.dgmemo as 备注,wg_infob.pgbh as 派工编号,sgry_infob.rybh as ' ','完工' as wg from user_card,sgry_infob,(select rybh,RYXM from ryinfo where BMBH='" & Trim(Str_bmbh) & "' and XTBH='" & Trim(Str_xtcode) & "' ) as ryinfo,bminfo,wg_infob where wg_infob.wgzt='N' and bminfo.BMtype='JYB' and wg_infob.ywbh=sgry_infob.ywbh and wg_infob.uphone=user_card.uphone and sgry_infob.rybh=ryinfo.rybh and sgry_infob.bmbh=bminfo.bmbh and bminfo.bmbh='" & Trim(Str_bmbh) & "'" & Str_query2 & " union " & _
" select yw_infob.ywbh as 业务流水号,ryinfo.RYXM as 施工人员,yw_infob.ywzl as 业务种类,yw_infob.uname as 用户名称,yw_infob.uphone as 用户号码,yw_infob.qh as 区号,yw_infob.uaddr as 联系地址,yw_infob.ulxfs as 联系方式,bminfo.BMMC as 受理营业厅,yw_infob.ywslsj as 受理时间,sgry_infob.wgdjsj as 完工时间,yw_infob.sbtg as 设备,yw_infob.ZJtype as 装机类型,sgry_infob.dgmemo as 备注,sgry_infob.pgbh as 派工编号,sgry_infob.rybh as ' ','未完工' as wg from yw_infob,sgry_infob,(select rybh,RYXM from ryinfo where BMBH='" & Trim(Str_bmbh) & "' and XTBH='" & Trim(Str_xtcode) & "' ) as ryinfo,bminfo where yw_infob.ywbh=sgry_infob.ywbh and sgry_infob.wgzt='D' and sgry_infob.bmbh=bminfo.bmbh and bminfo.bmbh='" & Trim(Str_bmbh) & "' and bminfo.bmtype='JYB' and sgry_infob.rybh=ryinfo.rybh " & Str_query1 & " order by ywslsj desc"
Str_query3 = "select yw_infob.ywbh as 业务流水号,ryinfo.RYXM as 施工人员,yw_infob.ywzl as 业务种类,yw_infob.uname as 用户名称,yw_infob.uphone as 用户号码,yw_infob.qh as 区号,yw_infob.uaddr as 联系地址,yw_infob.ulxfs as 联系方式,bminfo.BMMC as 受理营业厅,yw_infob.ywslsj as 受理时间,sgry_infob.wgdjsj as 完工时间,yw_infob.sbtg as 设备,yw_infob.ZJtype as 装机类型,sgry_infob.dgmemo as 备注,sgry_infob.pgbh as 派工编号,sgry_infob.rybh as ' ','未完工' as wg from yw_infob,sgry_infob,(select rybh,RYXM from ryinfo where BMBH='" & Trim(Str_bmbh) & "' and XTBH='" & Trim(Str_xtcode) & "' ) as ryinfo,bminfo where yw_infob.ywbh=sgry_infob.ywbh and sgry_infob.wgzt='D' and sgry_infob.bmbh=bminfo.bmbh and bminfo.bmbh='" & Trim(Str_bmbh) & "' and bminfo.bmtype='JYB' and sgry_infob.rybh=ryinfo.rybh " & Str_query1 & " order by ywslsj desc"
End If
Adodc1.RecordSource = Str_query3
Adodc1.Refresh
MSH.Refresh
aohan 2004-11-30
  • 打赏
  • 举报
回复
我处理mshflexgrid时没发现过你所说的问题,能否贴点代码上来看看你是怎么处理的
pingpangqiuliuji 2004-11-30
  • 打赏
  • 举报
回复
谢谢大家,我先去试一下。
成功了就给大家加分了
顺便问一下.row和.rowsel有什么区别
saiko 2004-11-30
  • 打赏
  • 举报
回复
有点不明白:
1.如果从 不能返回正确的当前选择的行 来说不是 mshflexgrid.row 应该是 mshflexgrid.rowsel

2.如果是返回记录集的行数的话 应该是 mshflexgrid.rows
zgvslch 2004-11-30
  • 打赏
  • 举报
回复
要把游标设为服务器端(或客户端,我记不清了,汗 ^_^!!)
rst.CursorLocation = adUseServer /adUseClient

还有个办法就是打开后移动到最后一条记录,再移动到最开始。
rst.movelast
rst.movefirst
pingpangqiuliuji 2004-11-30
  • 打赏
  • 举报
回复
没有那,我没对mshflexgrid控件属性改任何东西
zgvslch 2004-11-30
  • 打赏
  • 举报
回复
你是不是在mshflexgrid中排了序的?
如果那样就会和记录集里的顺序不一样了
saiko 2004-11-30
  • 打赏
  • 举报
回复
.row '是当前所操作的行
.rowsel '当前选中的行
pingpangqiuliuji 2004-11-30
  • 打赏
  • 举报
回复
都不行
等待中ing……
pingpangqiuliuji 2004-11-30
  • 打赏
  • 举报
回复
to aohao
不能象你那样,你所说的不行,为空的时候还是要显示的
再次谢谢大家,我去试一下tztz520你的办法。
tztz520 2004-11-30
  • 打赏
  • 举报
回复
你可以这样试一下.
就是每都先nothing


set MSH.RecordSource =nothing
set MSH.RecordSource =rs

1,451

社区成员

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

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