listcount 属性示例

下面的示例创建了一个列表框。列表框中的项的源是由 rowsourcetype 和 rowsource属性指定的数组。

listcount 用于对组合框或列表框的 list 属性指定的所有项进行循环遍历。

设置列表框的multiselect 属性为真(.t.),这样您就可以在列表框中有多个选择。在for?..燛ndfor 循环中用 listcount 属性可显示项或在列表框中所选的项。可用selected 和 list 属性来决定选择的项。

clear
dimension gamylistarray(10)
for gncount = 1 to 10  && fill the array with letters
   store replicate(chr(gncount+64),6) to gamylistarray(gncount)
endfor
frmmyform = createobject('form')  && create a form
frmmyform.closable = .f.  && disable the控件 menu box 
frmmyform.move(150,10)  && move the form
frmmyform.addobject('cmbcommand1','cmdmycmdbtn')  && add "quit" 命令 button
frmmyform.addobject('lstlistbox1','lstmylistbox')  && add list box control
frmmyform.lstlistbox1.rowsourcetype = 5  && specifies an array
frmmyform.lstlistbox1.rowsource = 'gamylistarray' && array containing listbox items
frmmyform.cmbcommand1.visible =.t.  && "quit" 命令 button visible
frmmyform.lstlistbox1.visible =.t.  && "list box visible
frmmyform.show  && display the form
read events  && start event processing
define class cmdmycmdbtn as commandbutton  && create 命令 button
   caption = '\<quit'  && caption on the 命令 button
   cancel = .t.  && default cancel 命令 button (esc)
   left = 125  && 命令 button column
   top = 210  && 命令 button row
   height = 25  && 命令 button height
   procedure click
      clear events  && stop event processing, close form
      clear  && clear main visual foxpro window
enddefine
define class lstmylistbox as listbox  && create listbox control
   left = 10  && list box column
   top = 10  && list box row
   multiselect = .t.  && allow selecting more than 1 item
procedure click
   activate screen
   clear
   ? "selected items:"
   ? "---------------"
   for ncnt = 1 to thisform.lstlistbox1.listcount
      if thisform.lstlistbox1.selected(ncnt)  && is item selected?
         ? space(5) + thisform.lstlistbox1.list(ncnt) && show item
      endif
   endfor
enddefine