100分关于msflexgrid或者mshflexgrid的问题,解决立即送分!!不够再加100!
我一直用的是datagrid控件,
请问我想在msflexgrid ,mshflexgrid中实现
1.奇偶行不同的背景颜色,表头不同的颜色,当前单元格又是另外一种颜色.
2.msflexgrid如何绑定显示一个记录集?如何实现对其基本的增删改操作?如何让一次只显示30条记录呢?
不好意思,内容实在太多,请贴源码或者发相关例子到 hanksblue@sina.com!
贴一下相关的datagrid中的操作.以便让各位少写些代码,
提数据事件
set conn = new connection
conn.cursorlocation = aduseclient
conn.open "联接字符串" ##########################################
set rs = new recordset
rs.open "select * from 表", conn, adopenstatic, adlockoptimistic
赋值给 datagrid 表
set datagrid1.datasource = rs
表刷新
datagrid1.refresh
若绑定textbox(数组):
text1(0).datafield = 字段1
text1(1).datafield = 字段2
.........
dim otext as textbox textbox
for each otext in me.text1
set otext.datasource = rs
next
添加事件和保存
rs.addnew
保存
rs![字段a] = text1.text
rs![字段b] = text2.text
rs.updatebatch adaffectall
删除
rs.delete
重新赋值给表
rs.requery
set datagrid1.datasource = rs
datagrid1.refresh
其他相关操作:
上一条
if not rs.bof then rs.moveprevious
if rs.bof and rs.recordcount > 0 then
已到最后返回
rs.movefirst
end if
下一条
if not rs.eof then rs.movenext 下一条
if rs.eof and rs.recordcount > 0 then
已到最后返回
rs.movelast
end if
第一条
if not rs.bof then rs.movefirst
最末
if not rs.eof then rs.movelast
_____________________________________________
这里没有问题1和问题2中关于限定显示记录数的代码?
再次表示感谢!解决立即送分!!!!
推荐阅读
1,
version 5.00
object = "{0ecd9b60-23aa-11d0-b351-00a0c9055d8e}#6.0#0"; "mshflxgd.ocx"
begin vb.form form1
caption = "form1"
clientheight = 3195
clientleft = 60
client = 345
clientwidth = 4680
linkic = "form1"
scaleheight = 3195
scalewidth = 4680
startupposition = 3 窗口缺省
begin mshierarchicalflexgridlib.mshflexgrid mshflexgrid1
height = 2775
left = 240
tabindex = 0
= 240
width = 3975
_extentx = 7011
_extenty = 4895
_version = 393216
rows = 20
cols = 20
fixedcols = 0
highlight = 0
fillstyle = 1
allowuserresizing= 3
_numberofbands = 1
_band(0).cols = 20
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 oldrow as long
private oldcol as long
private oldcolor as ole_color
private sub colflex()
dim i as integer
with mshflexgrid1
.fillstyle = flexfillrepeat
for i = .fixedrows + 1 to .rows - 1 step 2
.row = i
.col = .fixedcols
.colsel = .cols - 1
.cellbackcolor = vbinfobackground
next i
end with
end sub
private sub form_load()
oldrow = 0
oldcol = 0
oldcolor = mshflexgrid1.backcolorfixed
call colflex
end sub
private sub form_resize()
mshflexgrid1.move me.scaleleft, me.scale, me.scalewidth, me.scaleheight
end sub
private sub mshflexgrid1_rowcolchange()
dim nowrow as long
dim nowcol as long
dim nowcolor as ole_color
nowcol = mshflexgrid1.col
nowrow = mshflexgrid1.row
nowcolor = mshflexgrid1.cellbackcolor
mshflexgrid1.col = oldcol
mshflexgrid1.row = oldrow
mshflexgrid1.cellbackcolor = oldcolor
mshflexgrid1.col = nowcol
mshflexgrid1.row = nowrow
mshflexgrid1.cellbackcolor = vbred
oldcol = nowcol
oldrow = nowrow
oldcolor = nowcolor
end sub
2,太晚了,明天再说
双击cell重新定位rst对象,有了当前rst,删除,修改就不难了吧
一次只显示30条记录
可以用for 循环控制
for i=1 to 30
msflexgrid1.textmatrix(i,0)=rs!字段1
msflexgrid1.textmatrix(i,1)=rs!字段2
next i
同意楼上那位,不过我要说两句,得及时增加行
一般是有两个for 语句结合起来写的。把下面这句放在第一个for的结尾就可以了。
mshflexgrid1.rows=mshflexgrid1.rows+1


讨论区