第二十七讲 深入窗体 进一步学习数据窗口控件(二) 打印本页  
 
  这一讲中我们继续上一讲的内容,完成以键盘对数据窗口控件中的数据进行操纵。
  打开W_datawindow。
  在rb_search1和rb_search2单选按钮控件中添加如下程序
  dw_input.setfocus( )
  编写在dw_input控件中用上下键和Pageup,Pagedown键,实现控制dw_browse控件中的数据记录的上下滚动。
  打开dw_browse控件的Script,选择RowFocuschanged事件,这个事件是Datawindow控件的又一个重要的事件。当datawindow控件行的焦点发生变化时,系统将触发RowFocuschanged事件。写入:
  int cur_row
  cur_row=this.getrow()
  if cur_row>0 then
  this.selectrow(0,false)
  this.selectrow(cur_row,true)
  end if
   this.selectrow(0,false)
  this.selectrow(cur_row,true)
  运行
  我们再次打开刚才编写的Script(dw_browse的Rowfocuschanged事件)。我们用的是:
  this.selectrow(0,false)
  this.selectrow(cur_row,true)
  第一个Selectrow()函数是为了将上次高亮的行变为不亮,它的第一个参数是“0”;而第二个Selectrow()函数是为了选择当前行为高亮。这是为了配合dw_input控件中用上下键和Pageup,Pagedown键,实现控制dw_browse控件中的数据记录的上下滚动而编写的。
  在dw_input控件的Script画板中,定义一个名为“ue_dwnkey”事件,选择它的Event ID为“pbm_dwnkey”。并对这个键盘事件进行编程。
  if dw_browse.rowcount()>0 then
  end if
  if KeyDown(KeyDownArrow!) then
   dw_browse.ScrollNextRow()
   return(1)
  end if
   if KeyDown(KeyUpArrow!) then
   dw_browse.ScrollPriorRow()
   return(1)
   end if
   if KeyDown(KeyPageUp!) then
   dw_browse.ScrollPriorPage()
   return(1)
   end if
  if KeyDown (KeyPageDown!) then
  dw_browse.ScrollNextPage()
  return(1)
  end if
  运行程序
  在dw_input控件中使用回车键实现取数。
  打开dw_input控件的Script画板。
  定义一个新的用户自定义事件:“ue_dwnprocessenter”,选择Event ID 为“pbm_dwnprocessenter”。
  编写Script:
  int iv_currentrow
  回到Script
  string fname
  if dw_browse.rowcount()>0 then
  fname=dw_browse.getitemstring(iv_currentrow,"fname")
  dw_input.setitem(1,1,fname)
  end if
  打开dw_browse控件的script。进入rowfocuschanged事件,加入:
  iv_currentrow=cur_row
  运行
  编写排序程序
  进入rb_Sort1单选按钮的Script。写入:
  dw_browse.setsort("id A")
  dw_browse.sort()
  dw_browse.setsort("fname A")
  dw_browse.sort()
  在rb_sort3中添加:
  dw_browse.setsort("lname A")
  dw_browse.sort()
  运行