[已解决] 請問 listview 如何 filter 想要的字
本帖最后由 ipmitool 于 2016-10-22 18:45 编辑請問可以讓程式打開就判斷 count 大於 500 就在 >500 的欄位填入Yes嗎? (使用 _GUICtrlListView_SetItemText 設 Yes 字串)
然後 Filter 的時候也可以把整筆資料順利帶出
#include <Array.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <File.au3>
#include <Excel.au3>
#include <MsgBoxConstants.au3>
#include <FileConstants.au3>
#include <Date.au3>
#include <GuiStatusBar.au3>
Local $path, $aFileList, $aNewList
$path = @ScriptDir
$aFileList = _FileListToArray($path, "*.txt")
Local $iI, $iTimer, $hListView
GUICreate("Test Management v1.0", 800, 300)
$hListView = GUICtrlCreateListView("", 15, 15, 550, 268)
$cInput_Filter = GUICtrlCreateInput("", 610, 90, 140, 20)
$cButton_Filter = GUICtrlCreateButton("Filter", 600, 118, 75, 23)
$cButton_All = GUICtrlCreateButton("All", 680, 118, 75, 23)
GUISetState(@SW_SHOW)
_GUICtrlListView_AddColumn($hListView, "Tester", 100)
_GUICtrlListView_AddColumn($hListView, "Test Item", 100)
_GUICtrlListView_AddColumn($hListView, "Count > 500", 100)
_GUICtrlListView_AddColumn($hListView, "Count", 60)
_GUICtrlListView_AddColumn($hListView, "Last Record Time", 150)
If IsArray($aFileList) Then
ReDim $aNewList
; Local $sComboTxt = "所有"
For $i = 1 To UBound($aFileList) - 1 Step 1
$aNewList[$i] = $aFileList[$i]
$aNewList[$i] = FileReadLine($aFileList[$i], 1)
$aNewList[$i] = FileReadLine($aFileList[$i], 2)
$aNewList[$i] = FileReadLine($aFileList[$i], 3)
$aNewList[$i] = FileReadLine($aFileList[$i], 4)
; If Not StringInStr($sComboTxt, $aNewList[$i]) Then $sComboTxt &= "|" & $aNewList[$i]
Next
_GUICtrlListView_AddArray($hListView, $aNewList)
EndIf
While 1
$Msg = GUIGetMsg()
Switch $Msg
Case $GUI_EVENT_CLOSE
Exit
Case $cButton_Filter
_FilterItem(GUICtrlRead($cInput_Filter))
Case $cButton_All
_ShowAll()
EndSwitch
WEnd
Func _ShowAll()
EndFunc ;==>_ShowAll
Func _FilterItem($sText)
;Local $i
GUICtrlSendMsg($hListView, $LVM_DELETEALLITEMS, 0, 0)
GUICtrlCreateListViewItem($i,$hListView)
For $i = 0 To UBound($aNewList) - 1
If StringInStr($aNewList[$i], $sText) or StringInStr($aNewList[$i], $sText) or StringInStr($aNewList[$i], $sText) Then
GUICtrlCreateListViewItem($aNewList[$i] & "|" & $aNewList[$i] & "|" & $aNewList[$i] & "|" & $aNewList[$i] & "|" & $aNewList[$i], $hListView)
EndIf
Next
EndFunc ;==>_FilterItem
請問有大師可以幫幫忙嗎 本帖最后由 chzj589 于 2016-10-22 14:23 编辑
回复 1# ipmitool
If IsArray($aFileList) Then
ReDim $aNewList
; Local $sComboTxt = "所有"
For $i = 1 To UBound($aFileList) - 1 Step 1
$aNewList[$i] = $aFileList[$i]
$aNewList[$i] = FileReadLine($aFileList[$i], 1)
$aNewList[$i] = FileReadLine($aFileList[$i], 2)
$aNewList[$i] = FileReadLine($aFileList[$i], 3)
$aNewList[$i] = FileReadLine($aFileList[$i], 4)
$h8 = "Yes"
If $aNewList[$i] >= 500 Then
GUICtrlCreateListViewItem($aNewList[$i] & "|" & $aNewList[$i] & "|" & $h8 & "|" & $aNewList[$i] & "|" & $aNewList[$i], $hListView)
Else
GUICtrlCreateListViewItem($aNewList[$i] & "|" & $aNewList[$i] & "|" & $aNewList[$i] & "|" & $aNewList[$i] & "|" & $aNewList[$i], $hListView)
EndIf
; If Not StringInStr($sComboTxt, $aNewList[$i]) Then $sComboTxt &= "|" & $aNewList[$i]
Next
;_GUICtrlListView_AddArray($hListView, $aNewList)
EndIf
本帖最后由 chzj589 于 2016-10-22 14:23 编辑
回复 2# ipmitool
Func _FilterItem($sText)
GUICtrlSendMsg($hListView, $LVM_DELETEALLITEMS, 0, 0)
For $i = 0 To UBound($aNewList) - 1
$h8 = "Yes"
If $aNewList[$i] >= 500 Then
GUICtrlCreateListViewItem($aNewList[$i] & "|" & $aNewList[$i] & "|" & $h8 & "|" & $aNewList[$i] & "|" & $aNewList[$i], $hListView)
Else
EndIf
Next
EndFunc ;==>_FilterItem
本帖最后由 ipmitool 于 2016-10-22 18:15 编辑
回复 4# chzj589
謝謝您喔, 可是我查bbb也是出現兩組yes耶...
可以使用_GUICtrlListView_SetItemText 設 Yes 字串嗎?
可以用類似這樣嗎?Func _FilterItem($sText)
GUICtrlSendMsg($hListView, $LVM_DELETEALLITEMS, 0, 0)
For $i = 0 To UBound($aNewList) - 1
GUICtrlCreateListViewItem($aNewList[$i] & "|" & $aNewList[$i] & "|" & "" & "|" & $aNewList[$i] & "|" & $aNewList[$i], $hListView)
If $aNewList[$i] >= 500 Then
_GUICtrlListView_SetItemText($hListView, $i,"Yes",2)
Else
EndIf
Next
EndFunc ;==>_FilterItem 我感觉有不少人好像纯粹是为提问而来的, 跟直接求代码也差不了多少了. 回复 3# chzj589
搞定嘍~#include <Array.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <File.au3>
#include <Excel.au3>
#include <MsgBoxConstants.au3>
#include <FileConstants.au3>
#include <Date.au3>
#include <GuiStatusBar.au3>
Local $path, $aFileList, $aNewList
$path = @ScriptDir
$aFileList = _FileListToArray($path, "*.txt")
Local $iI, $iTimer, $hListView
GUICreate("Test Management v1.0", 800, 300)
$hListView = GUICtrlCreateListView("", 15, 15, 550, 268)
$cInput_Filter = GUICtrlCreateInput("", 610, 90, 140, 20)
$cButton_Filter = GUICtrlCreateButton("Filter", 600, 118, 75, 23)
$cButton_All = GUICtrlCreateButton("All", 680, 118, 75, 23)
GUISetState(@SW_SHOW)
_GUICtrlListView_AddColumn($hListView, "Tester", 100)
_GUICtrlListView_AddColumn($hListView, "Test Item", 100)
_GUICtrlListView_AddColumn($hListView, "Count > 500", 100)
_GUICtrlListView_AddColumn($hListView, "Count", 60)
_GUICtrlListView_AddColumn($hListView, "Last Record Time", 150)
If IsArray($aFileList) Then
ReDim $aNewList
; Local $sComboTxt = "所有"
For $i = 1 To UBound($aFileList) - 1 Step 1
$aNewList[$i] = $aFileList[$i]
$aNewList[$i] = FileReadLine($aFileList[$i], 1)
$aNewList[$i] = FileReadLine($aFileList[$i], 2)
$aNewList[$i] = FileReadLine($aFileList[$i], 3)
$aNewList[$i] = FileReadLine($aFileList[$i], 4)
; If Not StringInStr($sComboTxt, $aNewList[$i]) Then $sComboTxt &= "|" & $aNewList[$i]
Next
_GUICtrlListView_AddArray($hListView, $aNewList)
EndIf
While 1
$Msg = GUIGetMsg()
Switch $Msg
Case $GUI_EVENT_CLOSE
Exit
Case $cButton_Filter
_FilterItem(GUICtrlRead($cInput_Filter))
Case $cButton_All
_ShowAll()
EndSwitch
WEnd
Func _ShowAll()
EndFunc ;==>_ShowAll
Func _FilterItem($sText)
;Local $i
GUICtrlSendMsg($hListView, $LVM_DELETEALLITEMS, 0, 0)
GUICtrlCreateListViewItem($i,$hListView)
For $i = 0 To UBound($aNewList) - 1
$h8="Yes"
If StringInStr($aNewList[$i], $sText) or StringInStr($aNewList[$i], $sText) or StringInStr($aNewList[$i], $sText) and $aNewList[$i] > 500 Then
GUICtrlCreateListViewItem($aNewList[$i] & "|" & $aNewList[$i] & "|" & $h8 & "|" & $aNewList[$i] & "|" & $aNewList[$i], $hListView)
EndIf
If StringInStr($aNewList[$i], $sText) or StringInStr($aNewList[$i], $sText) or StringInStr($aNewList[$i], $sText) and $aNewList[$i] < 500 Then
GUICtrlCreateListViewItem($aNewList[$i] & "|" & $aNewList[$i] & "|" & $aNewList[$i] & "|" & $aNewList[$i] & "|" & $aNewList[$i], $hListView)
EndIf
Next
EndFunc ;==>_FilterItem
回复 5# ipmitool
修改两个代码后:
运行:
点击"Filter":
回复 8# chzj589
您好,請問您說哪兩個代碼? 回复 9# ipmitool
3楼与4楼的 回复 10# chzj589
謝謝您~ 回复 11# ipmitool
运行:
点击"Filter":
输入框查询,点击"搜索All":
点击"返回":
代码:
#include <Array.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <File.au3>
#include <Excel.au3>
#include <MsgBoxConstants.au3>
#include <FileConstants.au3>
#include <Date.au3>
#include <GuiStatusBar.au3>
Local $path, $aFileList, $aNewList
$path = @ScriptDir
$aFileList = _FileListToArray($path, "*.txt")
Local $iI, $iTimer, $hListView
GUICreate("Test Management v1.0", 800, 300)
$hListView = GUICtrlCreateListView("", 15, 15, 550, 268)
$cInput_Filter = GUICtrlCreateInput("", 600, 90, 155, 20)
$cButton_Filter = GUICtrlCreateButton("Filter", 600, 146, 75, 23)
$cButton_All = GUICtrlCreateButton("搜索All", 600, 118, 155, 23)
$cButton_du = GUICtrlCreateButton("返回", 680, 146, 75, 23)
GUISetState(@SW_SHOW)
_GUICtrlListView_AddColumn($hListView, "Tester", 100)
_GUICtrlListView_AddColumn($hListView, "Test Item", 100)
_GUICtrlListView_AddColumn($hListView, "Count > 500", 100)
_GUICtrlListView_AddColumn($hListView, "Count", 60)
_GUICtrlListView_AddColumn($hListView, "Last Record Time", 150)
If IsArray($aFileList) Then
ReDim $aNewList
; Local $sComboTxt = "所有"
For $i = 1 To UBound($aFileList) - 1 Step 1
$aNewList[$i] = $aFileList[$i]
$aNewList[$i] = FileReadLine($aFileList[$i], 1)
$aNewList[$i] = FileReadLine($aFileList[$i], 2)
$aNewList[$i] = FileReadLine($aFileList[$i], 3)
$aNewList[$i] = FileReadLine($aFileList[$i], 4)
$h8 = "Yes"
If $aNewList[$i] >= 500 Then
GUICtrlCreateListViewItem($aNewList[$i] & "|" & $aNewList[$i] & "|" & $h8 & "|" & $aNewList[$i] & "|" & $aNewList[$i], $hListView)
Else
GUICtrlCreateListViewItem($aNewList[$i] & "|" & $aNewList[$i] & "|" & $aNewList[$i] & "|" & $aNewList[$i] & "|" & $aNewList[$i], $hListView)
EndIf
; If Not StringInStr($sComboTxt, $aNewList[$i]) Then $sComboTxt &= "|" & $aNewList[$i]
Next
;_GUICtrlListView_AddArray($hListView, $aNewList)
EndIf
While 1
$Msg = GUIGetMsg()
Switch $Msg
Case $GUI_EVENT_CLOSE
Exit
Case $cButton_Filter
_FilterItem(GUICtrlRead($cInput_Filter))
Case $cButton_All
_ShowAll()
Case $cButton_du
_Showdu()
EndSwitch
WEnd
Func _Showdu()
GUICtrlSetData($cInput_Filter, "")
GUICtrlSendMsg($hListView, $LVM_DELETEALLITEMS, 0, 0)
If IsArray($aFileList) Then
ReDim $aNewList
; Local $sComboTxt = "所有"
For $i = 1 To UBound($aFileList) - 1 Step 1
$aNewList[$i] = $aFileList[$i]
$aNewList[$i] = FileReadLine($aFileList[$i], 1)
$aNewList[$i] = FileReadLine($aFileList[$i], 2)
$aNewList[$i] = FileReadLine($aFileList[$i], 3)
$aNewList[$i] = FileReadLine($aFileList[$i], 4)
$h8 = "Yes"
If $aNewList[$i] >= 500 Then
GUICtrlCreateListViewItem($aNewList[$i] & "|" & $aNewList[$i] & "|" & $h8 & "|" & $aNewList[$i] & "|" & $aNewList[$i], $hListView)
Else
GUICtrlCreateListViewItem($aNewList[$i] & "|" & $aNewList[$i] & "|" & $aNewList[$i] & "|" & $aNewList[$i] & "|" & $aNewList[$i], $hListView)
EndIf
Next
EndIf
EndFunc ;==>_Showdu
Func _ShowAll()
$cInput = GUICtrlRead($cInput_Filter)
GUICtrlSendMsg($hListView, $LVM_DELETEALLITEMS, 0, 0)
For $i = 0 To UBound($aNewList) - 1
$h8 = "Yes"
If $aNewList[$i] = $cInput Then
If $aNewList[$i] >= 500 Then
GUICtrlCreateListViewItem($aNewList[$i] & "|" & $aNewList[$i] & "|" & $h8 & "|" & $aNewList[$i] & "|" & $aNewList[$i], $hListView)
Else
GUICtrlCreateListViewItem($aNewList[$i] & "|" & $aNewList[$i] & "|" & $aNewList[$i] & "|" & $aNewList[$i] & "|" & $aNewList[$i], $hListView)
EndIf
EndIf
Next
EndFunc ;==>_ShowAll
Func _FilterItem($sText)
GUICtrlSetData($cInput_Filter, "")
GUICtrlSendMsg($hListView, $LVM_DELETEALLITEMS, 0, 0)
For $i = 0 To UBound($aNewList) - 1
$h8 = "Yes"
If $aNewList[$i] >= 500 Then
GUICtrlCreateListViewItem($aNewList[$i] & "|" & $aNewList[$i] & "|" & $h8 & "|" & $aNewList[$i] & "|" & $aNewList[$i], $hListView)
Else
EndIf
Next
EndFunc ;==>_FilterItem
先看看学习一下
页:
[1]