如何让用户选择需要显示的列?

hks 2002-08-06 09:23:59
如何让用户选择指定数据窗口中需要显示的列?请给出一个通用的方法?50分相谢。
...全文
79 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
rock_csdn 2002-08-07
  • 打赏
  • 举报
回复
不好意思,上面代码使用了一个f_depart_string()
//============================================================
// Function - f_depart_string
//------------------------------------------------------------
// Description:分解字符串
//------------------------------------------------------------
// Arguments:
//
// string s
// string to be depart待分解的串
// string gap_string
// string used to seprate the string, such as ',','\' etc.support string with serveral chars as '~t~n'
// 分隔符,如',' '\'等,可支持多位分隔符,如'~t~n'
// string str[](REF)
// array to store the string be seprated
// 用于存放分解结果的串数组(指针引用)
//------------------------------------------------------------
// Returns: (INTEGER)
// num of the child strings after depart
// 分解得到的子串个数
//------------------------------------------------------------
// 调用举例:
// string ls_col[], gap_string='~t~n', ls_exp='deptno~t~ndeptname~t~ndeptattr'
// long ll_colNum
// ll_colNum = f_depart_string(ls_exp, gap_string, ls_col)
// 结果:
// ll_colNum : 3
// ls_col[1] : deptno
// ls_col[2] : deptname
// ls_col[3] : deptattr
//------------------------------------------------------------
// Author: Date:
//============================================================
int pos1, pos2, counter
string ls_tmp

counter = 0
do
counter ++
pos1 = pos(s, gap_string)
if pos1 = 0 then pos1 = len(s) +1
ls_tmp = left(s, pos1 - 1)
s = mid(s, pos1 +len(gap_string))
pos1 = pos(s,gap_string)
str[counter] = ls_tmp
IF isnull(ls_tmp) or ls_tmp = '' THEN continue
loop until len(s)=0

return upperbound(str)
rock_csdn 2002-08-07
  • 打赏
  • 举报
回复
提供一个可以反复选择栏目的代码。仅供参考。欢迎指正

将欲 选择需要显示的列之数据窗口传入,作为窗口的实例级变量idw

然后在打开的时候读出要列的信息并显示在一数据窗口中
此数据窗口为外部数据源,只有4列
visible long//是否可见
visible_pre long//原显示是否可见
colname_eng string//栏英文名
colname_chi string//栏中文名

窗口open event:
long i, num, j, row
string s, ls_tmp, ss, ls_object[]

//1 取得当前数据窗口列属性:列名 可见属性 缺省宽度
s = idw_source.describe('datawindow.objects')

num = f_depart_string(s, '~t', ls_object)
if num =0 then return messagebox('失败','没有取得任何备用列!')

j =0
for i = 1 to num
ls_tmp = ls_object[i]
s = idw_source. describe(ls_tmp +'.type')
if s <>'column' and left(lower(s),5)<>lower('Compu') then continue

//get column name
s = idw_source. describe(ls_tmp +'_t.text')
if s ='?' or s ='!' then continue//s ='无中文列名字段'
j ++
colname_eng[j] = ls_tmp
colname_chi[j] = s
//visible now?
ss = idw_source.describe(ls_tmp+'.visible')
col_visible [j] = ss
ss = idw_source.describe(ls_tmp+'.width')
if long(ss)= 0 then col_visible[j] ='0'
if ss ='0' then debugbreak()
//default width
col_width[j] = integer(ss)
if ss ='0' then
ss = idw_source.describe(ls_tmp +'.tag')
if not(ss ='?' or ss ='!') then
ss = mid( ss, pos(ss, WIDTH_FLAG) +len(WIDTH_FLAG) )
col_width[j] = long(ss)
end if
end if
if col_width[j]< 1 then col_width [j] = 200
next

//2 将列属性填入备选列表
if j < 1 then return
for i = 1 to j
row = dw_1.insertRow(0)
dw_1.object.visible[row] = long(col_visible[i])
dw_1.object.visible_pre[row] = long(col_visible[i])
dw_1.object.colname_eng[row] = colname_eng[i]
dw_1.object.colname_chi[row] = (colname_chi[i])
next

//确定按钮事件:确认选择的栏后的处理
long i, num
long ll_width
string ls_visible, ls_visible_pre, ls_col, ls_width, ls_tmp

num = dw_1.rowcount()
//根据设置情况,动态修改数据窗口列宽度
for i = 1 to num
ls_col = dw_1.object .colname_eng[i]
ls_visible = string(dw_1.object .visible[i])
ls_visible_pre = string(dw_1.object .visible_pre[i])
ls_width = string(col_width[i])

if ls_visible = ls_visible_pre then continue
if ls_visible ='0' then
//保存原宽度至TAG

ls_tmp = idw_source.describe( ls_col+'.tag')
if ls_tmp ='?' then ls_tmp =''
if pos(ls_tmp, WIDTH_FLAG) =0 then ls_tmp += WIDTH_FLAG + ls_width
idw_source.modify(ls_col+'.tag="'+ls_tmp+'"')
//修改宽度->0
idw_source.modify(ls_col+'.width=0')
idw_source.modify(colname_chi[i]+ '.width=0')
elseif ls_visible ='1' then
idw_source.modify(ls_col+'.width="'+ls_width+'""~t'+ ls_col+'.visible="1"')
idw_source.modify(colname_chi[i]+'.x="'+idw_source.describe(ls_col+'.x')+'"~t'+colname_chi[i]+ '.width="'+ls_width+'"~t'+ colname_chi[i]+'.visible="1"')
end if
//
next

close(parent)
hks 2002-08-07
  • 打赏
  • 举报
回复
感谢各位热忱相助。
第一、以前没有发过这类问题的贴子。由于搜索时总是得到一个“服务器忙”,所以不得不发贴求助。
第二、贴子当然可以加分。只要能解决问题,愿为各位早日拿到五星加油。
第三、我要的是一个能够临时、反复地修改多个数据窗口的可见列的通用方法。
我做的与rock_csdn(乱云)相似:
//w_select_col.open event
//两个数据窗口(均为外部数据源):dw_col和dw_ref,dw_col中有列col_check(单选框)、col_label(中文的列标签)、col_name(列标签的对象名,不可见)、col_x(列标签的X坐标,不可见);dw_ref不可见,有列col_name(列对象名)、col_x(列的X坐标)
//使用了col_x以便确定两个数据窗口中列的对应关系

int p, i
string ls_str, ls_name, ls_type
//instance varible datawindow dw_param

dw_param = message.PowerObjectParm
ls_str = dw_param.Describe("DataWindow.Objects")
do while true
p = Pos(ls_str, ' ')
if p = 0 then exit
ls_name = left(ls_str, p - 1)
ls_str = Replace(ls_str, 1, p, '') //delete the tab character found and all before it

ls_type = dw_param.Describe(ls_name + ".type")
if ls_type = "text" then
i = dw_col.InsertRow(0)
dw_col.SetItem(i, "col_name", ls_name)
dw_col.SetItem(i, "col_x", dw_param.Describe(ls_name + ".X"))
dw_col.SetItem(i, "col_label", dw_param.Describe(ls_name + ".Text"))
else
if ls_type = "column" then
i = dw_ref.InsertRow(0)
dw_ref.SetItem(i, "col_name", ls_name)
dw_ref.SetItem(i, "col_x", dw_param.Describe(ls_name + ".X"))
end if
end if
loop

dw_col.SetSort("col_x A, col_name A")
dw_col.Sort()
dw_ref.SetSort("col_x A, col_name A")
dw_ref.Sort()
//todo: set col_check=1 in dw_col if dw_ref.<col_name>.visible=false

因为列标签命名的随意性,列标签的name不一定是列的name+"_t",所以分别对各个对象的type进行判断;出现了两个问题:1.dw_ref比dw_col多了一行,原因是dw_param中有一列设计时就没有加到grid中;2.col_x列全部是空的,没有取出任何数据;3.设计时某一列标签的text为空,使用了表达式,结果把表达式取出来了。
balloonman2002 2002-08-06
  • 打赏
  • 举报
回复
你可参考:
http://www.csdn.net/expert/topic/837/837819.xml?temp=.1650812
里面问题和你的一样,:),不会是你问的吧,:)
qinqindodo 2002-08-06
  • 打赏
  • 举报
回复
如果临时,用Modify修改visible不行吗?
如果永久,取出数据窗口的语法保存再重新创建
取得语法好像是 dw.object.datawindow.syntax
佣工7001 2002-08-06
  • 打赏
  • 举报
回复
就给50分,能不能再加点~
简单的说,用户制定一列后
用Modify(“Destroy ObjName”)或Modify(“Destroy Column Colname”)的方法删除列,或设置宽度为0,然后存道配置文件中,每次达开的时候,执行以便

1,076

社区成员

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

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