PB中datawindow常用技巧

1、如何讓存儲文件目錄的列,顯示圖片?

答:選擇對應的column的display as picture屬性爲true

2、如何複製grid類型的所選擇的行的數據到系統剪切板?

答:string ls_selected

ls_selected=dw_1.Object.DataWindow.Selected.Data

clipbord(ls_selected)

4、如何設置的DW底色?

在DW的editsource中改變color的值

5、如何將Grid風格改成自由格式?

在DW的editsource中將processing=1的1改爲0

6、要新建一個表A但風格和現有表格B風格一樣,怎麼將A錶快速設置成表B風格?

複製B表C,在C表的DW中的editsource中將表名和字段名改成A表的,即可

7、如何實現gird風格的datawindow的多欄表頭?

答:添加 text到header帶區,並設置band屬性爲foreground保存,edit source 修改text的x和width屬性表達式如下:

x="100~t integer(describe('firstcol.x')" width="100~tinteger(describe('lastcol.x')) - integer(describe('firstcol.x')) +integer(describe('lastcol.width'))

8、如何過濾dddw編輯風格的顯示值爲指定值的記錄?

答:dw_1.setfilter("lookupdisplay('column_name')='"+ls_display_value_your+"'")

dw_1.filter()

9、如何設置datawindow的某一列爲空?

答:string ls_temp[]

setnull(ls_temp)

dw_1.object.columnname.primary.current=ls_temp

10、如何設置datawindow的單雙行不同顏色間隔?

答:在detail帶區的color屬性表達式中寫上if(mod (getrow(),2)=1 ,rgb(255,0,0),rgb(0,255,0)),如果是當前行以第三種顏色表示,表達式如下:if(getrow()=current(), rgb(255,0,0),if(mod(getrow(),2)=1 ,rgb(0,0,255),rgb(0,255,0)))

11、如何獲取指定名稱的datawindowobject?

答:DWObject ldwo_use,ldwo_abc ldwo_use = dw_1.Object ldwo_abc = ldwo_use.__get_attribute("t_1",FALSE)//t_1爲datawindow中text對象的名稱

12、如何縮放datawindow的打印大小?

答:dw_1.object.datawindow.zoom=150 or dw_1.object.datawindow.zoom=75

13、如何在已過濾後的數據基礎上對datawindow進行過濾?

答:dw_1.setfilter(dw_1.describe("datawindow.table.filter")+your_join+your_new_filter)

dw_1.filter()

14、如何在datawindow中顯示動態時間?

答:建立一個計算域,表達式爲string(datetime(today(),now()),'yyyy年mm月dd日 hh點mm分ss秒'),同時設置datawindow的屬性dw_1.Object.DataWindow.Timer_Interval=500

15、如何讓帶用title bar的datawindow控件的標題欄誠活動窗口的顏色?

答:外部函數定義:

funcation logn SetActiveWindow(long hwnd ) Library "user32.dll"

datawindow控件的clicked事件代碼:

setactivewindow(handle(this))

16、如何設置datawindow的當前行指示圖標?

答:在datawindow中建立一個計算列,expression爲'',並將該計算列移動爲datawindow的第一個列,在datawindow控件的

rowfocuschanged事件中寫入代碼:

SetRowFocusIndicator(hand!)或setrowfucsindicator(p_1)//p_1爲窗口上的picture控件名

17、如何通過代碼打開dddw?

答:定義外部函數引用聲明

SUBROUTINE keybd_event( int bVk, int bScan, int dwFlags, int dwExtraInfo) LIBRARY "user32.dll"

代碼如下: [constant integer VK_F4 = 115

dw_1.SetFocus()

dw_1.SetColumn( "dept_head_id" ) //設置當前dddw

keybd_event( VK_F4,0,0,0 ) // 按下F4鍵

keybd_event( VK_F4,0,2,0 ) // 釋放F4鍵

18、如何打印datawindow的內容到文件中?

答: dw_1.object.datawindow.print.fileName ="c:/temp.prn"

dw_1.print()

19、如何設置dddw的初始值?

答:dw_1.object.columnname.Initial="your_initial_value"

20、如何只顯示不同的數據?

答:dw_1.filter("isnull(columnname[-1]) and columnname<>columnname[-1]")

dw_1.filter()

21、如何讓帶有title bar的datawindow不可以移動?

答:在datawindow的自定義事件ue_nchittest(pbm_nchittest)中寫入如下代碼:

return 1

22、如何在N-UP顯示風格中建立基於第N欄中的列的計算列?

答:如column有兩列,number和price ,並顯示爲兩欄,則第一欄的cost計算列的expression爲number*price,第二欄的cost_1計算列的expression爲number[1]*price[1]

23、如何清空ddlb或edit.codetable中項目?

答:dw_1.Object.columnname.Values=""

24、如何實現指定的column的字體旋轉90度?

答:dw_1.object.columnname.font.Escapement ="900"

25、如何獲取datawindow的sql代碼?

答: 可以通過以下四種方法獲取sql代碼:

string szselect

szselect=dw_1.describe("datawindow.table.select")

szselect=dw_1.describe("datawindow.table.sqlselect")

szselect=dw_1.describe("datawindow.table.select.attribute")

szselect=dw_1.getsqlselect()

27、如何獲取datawindow對象佔有的虛擬存儲的容量?

答:使用datawindow.storage屬性

舉例:在datawindow控件的retrieverow事件中,寫如如下代碼:

long lstorage

lstorage=long(dw_1.object.datawindow.storage)

if lstorage>50000 then dbcancel()

28、如何連續在同一張紙打印兩個數據窗口?

答:dw_1.object.datawindow.print.filename="temp.prn"

dw_2.object.datawindow.print.filename="temp.prn"

dw_1.print()

dw_2.print()

29、如何設置datawindow分組後每個分組中的記錄號?

答:建立一個計算列,expression爲 getrow() - first(getrow() for group 1)+1

30、如何實現在datawindow中只有新增的行,纔可以編輯?

答:在所有的column的protect屬性表達式中寫入以下表達式:

if(isrownew(),'0','1')

31、除了循環以外,有沒有更好的方法統計數據窗口中處於選中狀態的行數?

一般習慣於使用循環來統計數據窗口中處於選中狀態的行數,有沒有更好的方法?其實此問題在應用上用處不大,討論一下,活躍一下思維還是有好處的。

方法一: long ll_Selected ll_Selected = long(dw_1.describe("evaluate('sum( if(IsSelected(), 1, 0) for all)',1)"))

方法二: long ll_Selected ll_Selected = long(dw_1.describe("evaluate('count(IsSelected() for all)',1)"))

方法三:upperbound(dw_1.Object.Data.Selected)

32、問:怎麼讓PB只打印當前記錄,是用Free格式製作的數據窗口!

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

答:

DataStore ldt_temp

long ll_Row , ll_Rows

ll_Rows = dw_XX.Rowcount()

If ll_Rows = 0 Then GoTo the_end

If ll_Rows = 1 Then

dw_XX.Print()

GoTo the_end

End if

dw_XX.SetRedraw(False)

ldt_temp = Create DataStore

ldt_temp.DataObject = dw_XX.DataObject

ll_Row = dw_XX.GetRow()

dw_XX.RowsMove(1 , ll_Rows , Primary! , ldt_temp , 1 , Primary!)

ldt_temp.RowsMove(ll_Row , ll_Row , Primary! , dw_XX , 1 , Primary!)

dw_XX.Print()

dw_XX.RowsMove(1 , 1 , Primary! , ldt_temp , ll_Row , Primary!)

ldt_temp.RowsMove(1 , ll_Rows , Primary! , dw_XX , 1 , Primary!)

Destroy ldt_temp

dw_XX.SetRedraw(True)

the_end:

// 只用將上述腳本拷入到打印部分即可,dw_XX爲被打印的free型數據窗口,該方法可保證dw_XX中的數據在打印前後包括sort等屬性均不發生任何改變,但效率較低,不宜用在數據量太大的數據窗口中,當然,考慮到打印本身速度就比較慢,所以3000行數據是可以採用這種方法並讓用戶接受的。若在同一窗口上存在與dw_XX共享的grid數據窗口並且與dw_XX同時顯示,則需要與dw_one一起SetRedraw()

38、字段如何自動換行的同時且自動高度?

答:將數據窗口中相應列的auto horz scroll 爲不選中,選中autosize height 將detail的autosize height選中。在數據窗口retrieve 後調用下面函數即可 uf_set_text(datawindow adw_content,string as_columns,boolean,ab_ignoreblank) /************************************************************* describe: 在數據窗口adw_content中,在as_columns中包含的列中插入空格 args: as_columns 要操作的多個列,列間用逗號隔開 *************************************************************/ if (not isvalid(adw_content)) or isnull(as_columns) or len(as_columns)<1 or isnull(ab_ignoreblank) then return -1 n_cst_string lnv_string string ls_column[] , ls_width ,as_source,as_replaced ,ls_temp int li_upperbound , li_width , li_column , li_fontWidth, li_counter long ll_rowcount , ll_row , ll_totalstep int li_yield lnv_string.of_parsetoarray(as_columns,',',ls_column) li_upperbound = upperbound(ls_column) ll_rowcount = adw_content.rowcount() if li_upperbound<1 or ll_rowcount<1 then return -1 openwithparm(w_waiting,this) ib_cancel = false iw_frame.enabled = false ll_totalstep = ll_rowcount * li_upperbound w_waiting.uf_register(ll_totalstep) for li_column = 1 to li_upperbound ls_width = adw_content.describe(ls_column[li_column]+".width") li_width = integer(ls_width) if ls_width='!' or ls_width='?' or li_width=0 then continue end if //ls_temp = adw_content.describe(ls_column[li_column]+".Font.property { = 'width' }") //messagebox(ls_column[li_column]+".Font.property { = 'width' }",ls_temp) //return 1 li_fontwidth = 27 li_counter = li_width / li_fontWidth for ll_row=1 to ll_rowcount if ib_cancel then iw_frame.enabled = true return 0 //pressed cancel button end if as_source = adw_content.getitemstring(ll_row,ls_column[li_column]) as_replaced = uf_insertstring(as_source,li_counter,' ',false) if as_replaced<>as_source then adw_content.setitem(ll_row,ls_column[li_column],as_replaced) end if w_waiting.uf_stepit() next next close(w_waiting) iw_frame.enabled = true return 1

39、如何使dw的列不可移動,不可調整列寬?

答:在datawindow的cilcked事件寫 if row=0 then return 1 end if

40.光標跳轉到數據窗口的某一行某一列

dw_1.scrolltorow(ll_row) dw_1.setcolumn(ll_column)

41 如何使光標指向每頁第一行?

long ll_firstrowonpage=long(dw_1.describe("datawindow.firstrowonpage"))

dw_1.scrolltorow(ll_firstrowonpage)

dw_1.setrow(ll_firstrowonpage)

42. Grid的窗口如何使第一列固定不動?

①選上data OBJECT的HSplitScroll屬性 ②在constructor事件中: dw_1.Object.DataWindow.HorizontalScrollSplit=integer(dw_1.describe("#1.width")) //第一列的寬度 ③在scrollhorizontal事件中: int i

if pane = 1 then

   i = integer(this.OBJECT.datawindow.horizontalscrollposition2)

   if i < 1 or isnull(i) then return

   if scrollpos > 0 then

      this.OBJECT.datawindow.horizontalScrollPosition = 0

   end if

else

   i = integer(this.Object.DataWindow.HorizontalScrollSplit)

   if i < 1 or isnull(i) then return

   if i > scrollpos then

       this.OBJECT.datawindow.horizontalScrollPosition2 = i

   end if

end if

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章