Author Topic: Listbox 慣常使用方式(程式碼取自CashierXtra)  (Read 4371 times)

admin

  • Administrator
  • *****
  • Posts: 0
    • View Profile
Listbox 慣常使用方式(程式碼取自CashierXtra)
« on: December 04, 2011, 06:53:21 PM »
初始化Listbox 欄數,大小樣式及欄目名稱等
Code: [Select]
Private Sub initlstBrowse()
  lstbrowse.TabStop = False
  lstbrowse.ColumnsResizable=true
  lstbrowse.ScrollBarHorizontal=false
  lstbrowse.ScrollBarVertical=true
  lstbrowse.AutoHideScrollbars=true
  lstbrowse.SelectionType=listbox.SelectionSingle
  lstbrowse.HasHeading=true
  lstbrowse.ColumnCount = 8
  lstbrowse.DeleteAllRows
  lstbrowse.DefaultRowHeight=30
  lstbrowse.AutoDeactivate=false
 
  lstbrowse.Column(cntautoid).widthExpression ="0"
  lstbrowse.Column(cntplucode).widthExpression ="60"
  lstbrowse.ColumnAlignment(cntplucode)=listbox.Aligncenter
  lstbrowse.Column(cntdescription).widthExpression ="*"
  lstbrowse.ColumnAlignment(cntdescription)=listbox.AlignLeft
  lstbrowse.Column(cntdepartmentid).widthExpression ="0"
  lstbrowse.Column(cntbarcode).widthExpression ="120"
  lstbrowse.ColumnAlignment(cntbarcode)=listbox.Alignleft
  lstbrowse.Column(cntprice).widthExpression ="70"
  lstbrowse.ColumnAlignment(cntprice)=listbox.AlignRight
  lstbrowse.Column(cntstatus).widthExpression ="80"
  lstbrowse.ColumnAlignment(cntstatus)=listbox.Aligncenter
  lstbrowse.Column(cntlastupdate).widthExpression ="100"
  lstbrowse.ColumnAlignment(cntlastupdate)=listbox.Alignleft
 
  lstbrowse.Heading(cntplucode)=GetUILanguage("caption_string", 75, gUIParentLCID)
  lstbrowse.Heading(cntdescription)=GetUILanguage("caption_string", 77, gUIParentLCID)
  lstbrowse.heading(cntbarcode)=GetUILanguage("caption_string", 76, gUIParentLCID)
  lstbrowse.heading(cntprice)=GetUILanguage("caption_string", 79, gUIParentLCID)
  lstbrowse.Heading(cntstatus)=GetUILanguage("caption_string", 80, gUIParentLCID)
  lstbrowse.Heading(cntlastupdate)=GetUILanguage("caption_string", 81, gUIParentLCID)
   
End Sub

塡入資料記錄至Listbox
Code: [Select]
Private Sub FilllstBrowse(optional tmpMethod as integer=0)
  Dim tmpSQL As String
  select case tmpMethod
  case 1
    tmpSQL = "select * from pluitem order by autoid desc limit 1"
   
  case else
    tmpSQL = "select * from pluitem order by plucode desc"
    lstbrowse.DeleteAllRows
   
  end select
 
  grsOpen=gdbConnection.SQLSelect(tmpsql)
 
  if grsopen<> nil then
    While Not (grsOpen.EOF)
      lstbrowse.addrow grsOpen.Field("autoid").stringvalue
      lstbrowse.cell(lstbrowse.LastIndex,cntplucode)= grsOpen.Field("plucode").StringValue
      lstbrowse.cell(lstbrowse.LastIndex,cntdescription)=grsOpen.Field("description").stringvalue
      lstbrowse.cell(lstbrowse.LastIndex,cntbarcode)=grsOpen.Field("barcode").stringvalue
      lstbrowse.cell(lstbrowse.LastIndex,cntdepartmentid)=grsOpen.Field("departmentid").stringvalue
      lstbrowse.cell(lstbrowse.LastIndex,cntprice)=format(grsOpen.Field("price").CurrencyValue,"#,###,##0.0")
      lstbrowse.cell(lstbrowse.LastIndex,cntstatus)=grsOpen.Field("status").stringvalue
      lstbrowse.cell(lstbrowse.LastIndex,cntlastupdate)=str(dbltodate(grsOpen.Field("lastupdate").doublevalue))
      grsOpen.MoveNext
    wend
    grsopen.close
  End If
 
Exception Err
  CatchErrorType(Err,CurrentMethodName)
 
End Sub

更新Listbox的內容, 通常於儲存修改現存的記錄後使用, 這樣不需要重新載入整個瀏覧的表格
Code: [Select]
Private Sub UpdateLstBrowse()
  lstBrowse.cell(pintcurrentrow,cntplucode)=txtbox(0).text
  lstBrowse.cell(pintcurrentrow,cntbarcode)=txtbox(1).text
  lstBrowse.cell(pintcurrentrow,cntdescription)=txtbox(2).text
  lstBrowse.cell(pintcurrentrow,cntprice)=Txtbox(3).Text
  lstBrowse.cell(pintcurrentrow,cntstatus)=str(integer(chkplu.State))
  lstBrowse.cell(pintcurrentrow,cntdepartmentid)=ppmplu.RowTag(ppmplu.ListIndex)
  lstBrowse.cell(pintcurrentrow,cntlastupdate)=lblupdate.text
End Sub
« Last Edit: December 04, 2011, 07:37:08 PM by Roy Chan »