【已解决】如何删除列表框某项目的同时删除ini里对应的该项目!
本帖最后由 xuanfeng1234567 于 2010-6-30 23:09 编辑关键字是从1开始递增的,不知道该如何删除,忘高手指教!
$hanghao +=1
_GUICtrlListView_DeleteItemsSelected ($GListView)
GUICtrlCreateListViewItem($Rinput02 & "|" & $Rdate02 & "|" & $Rtime102 &":"& $Rtime202 &":"& $Rtime302 & "|" & $Redit02,$GListView);写进列表框
IniWrite($ShuJu,"Section",$HangHao,$Rinput02 & "|" & $Rdate02 & "|" & $Rtime102 &":"& $Rtime202 &":"& $Rtime302 & "|" & $Redit02) ;写入ini里
弄个简单且完整点的代码吧,这样人家也不好给你改或者解释~ 谢谢afan的热心帮注!
#include<GUIConstants.au3>
#Include <GuiListView.au3>
#include <DateTimeConstants.au3>
Dim $HangHao
$ShuJu = @ScriptDir & "\beiwanglu.ini"
$bei = GUICreate("备忘录",400,240)
$GListView= GUICtrlCreateListView (" 事件 | 日期 |指定的时间| 备注 ",5,5,310,156) ;创建Listview控件,
_GUICtrlListView_SetExtendedListViewStyle($GListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
GUICtrlCreateLabel("现在时刻:",5,180,75,30)
$time = GUICtrlCreateLabel("",70,180,230,30)
$add = GUICtrlCreateButton("添加事件",320,10,70,30)
$del = GUICtrlCreateButton("删除事件",320,130,70,30)
GUISetState(@SW_SHOW)
;添加窗口
$tianjia = GUICreate("添加事件提醒",235,280)
GUICtrlCreateLabel("事件名称:",10,20,70,30)
$Rinput = GUICtrlCreateInput("",70,15,155,20)
GUICtrlCreateLabel("指定日期:",10,50,70,30)
$Rdate = GUICtrlCreateDate(@YEAR&"/"&@MON&"/"&@MDAY,70,45,155,20)
GUICtrlCreateLabel("指定时间:",10,84,70,30)
$Rtime1 = GUICtrlCreateCombo("00",70,80,35,20)
GUICtrlSetData(-1,"01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24")
GUICtrlCreateLabel("时",106,84,15,20)
$Rtime2 = GUICtrlCreateCombo("00",122,80,35,20)
GUICtrlSetData(-1,"01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60")
GUICtrlCreateLabel("分",158,84,15,20)
$Rtime3 = GUICtrlCreateCombo("00",174,80,35,20)
GUICtrlSetData(-1,"01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60")
GUICtrlCreateLabel("秒",210,84,15,20)
GUICtrlCreateLabel("备 注:",10,114,70,30)
$Redit = GUICtrlCreateEdit("",10,135,215,110)
$Rok = GUICtrlCreateButton("确定",50,250,60,25)
$Rcancle = GUICtrlCreateButton("取消",120,250,60,25)
_duqu()
While 1
$Rinput0 = GUICtrlRead($Rinput)
$Rdate0 = GUICtrlRead($Rdate)
$Rtime10 = GUICtrlRead($Rtime1)
$Rtime20 = GUICtrlRead($Rtime2)
$Rtime30 = GUICtrlRead($Rtime3)
$Redit0 = GUICtrlRead($Redit)
$a = '<' & ' '& @YEAR & '年' & @MON & '月' & @MDAY & '日' &' '&'>'& ' ' & @HOUR & ':' & @MIN & ':' & @SEC ;时间
If GUICtrlRead($time) <> $a Then GUICtrlSetData($time,$a)
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
Exit
Case $add
_tianjia()
Case $del
_del()
Case $Rok
_Rok()
Case $Rcancle
_cancle()
EndSwitch
WEnd
Func _tianjia()
GUISetState(@SW_SHOW,$tianjia)
GUISetState(@SW_DISABLE,$bei)
WinSetTrans($bei,"",150)
EndFunc
Func _del()
$d = MsgBox(1+64,"提示","是否删除选中项目?")
If $d = 1 Then
_GUICtrlListView_DeleteItemsSelected ($GListView)
ElseIf $d = 2 Then
MsgBox(64,"","你放弃删除选中项!")
EndIf
EndFunc
Func _cancle()
GUICtrlSetData($Rinput,"")
GUICtrlSetData($Rdate,@YEAR&"/"&@MON&"/"&@MDAY)
GUICtrlSetData($Rtime1,"00")
GUICtrlSetData($Rtime2,"00")
GUICtrlSetData($Rtime3,"00")
GUICtrlSetData($Redit,"")
GUISetState(@SW_HIDE,$tianjia)
GUISetState(@SW_ENABLE,$bei)
WinSetTrans($bei,"",250)
EndFunc
Func _Rok()
$hanghao = _GUICtrlListView_GetItemCount($GListView)
$hanghao +=1
If $Rinput0 <> "" And $Rdate0 <> "" And $Rtime10 <> ""And $Rtime20 <> "" And $Rtime30 <> "" And $Redit0 <> "" Then
GUICtrlCreateListViewItem($Rinput0 & "|" & $Rdate0 & "|" & $Rtime10 &":"& $Rtime20 &":"& $Rtime30 & "|" & $Redit0,$GListView)
IniWrite($ShuJu,"Section",$HangHao,$Rinput0 & "|" & $Rdate0 & "|" & $Rtime10 &":"& $Rtime20 &":"& $Rtime30 & "|" & $Redit0)
GUISetState(@SW_HIDE,$tianjia)
GUICtrlSetData($Rinput,"")
GUICtrlSetData($Rdate,@YEAR&"/"&@MON&"/"&@MDAY)
GUICtrlSetData($Rtime1,"00")
GUICtrlSetData($Rtime2,"00")
GUICtrlSetData($Rtime3,"00")
GUICtrlSetData($Redit,"")
GUISetState(@SW_ENABLE,$bei)
WinSetTrans($bei,"",250)
EndIf
EndFunc
Func _duqu()
_GUICtrlListView_DeleteAllItems($GListView)
$var = IniReadSection($ShuJu,"Section")
If Not @error Then
For $i = 1 To $var
GUICtrlCreateListViewItem($var[$i], $GListView)
Next
EndIf
EndFunc afan哥,带码给你了,帮我改一下哦! 本帖最后由 410521a 于 2010-6-30 21:44 编辑
#include<GUIConstants.au3>
#Include <GuiListView.au3>
#include <DateTimeConstants.au3>
Dim $HangHao
$ShuJu = @ScriptDir & "\beiwanglu.ini"
$bei = GUICreate("备忘录",400,240)
$GListView= GUICtrlCreateListView (" 事件 | 日期 |指定的时间| 备注 ",5,5,310,156) ;创建Listview控件,
_GUICtrlListView_SetExtendedListViewStyle($GListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
GUICtrlCreateLabel("现在时刻:",5,180,75,30)
$time = GUICtrlCreateLabel("",70,180,230,30)
$add = GUICtrlCreateButton("添加事件",320,10,70,30)
$del = GUICtrlCreateButton("删除事件",320,130,70,30)
GUISetState(@SW_SHOW)
;添加窗口
$tianjia = GUICreate("添加事件提醒",235,280)
GUICtrlCreateLabel("事件名称:",10,20,70,30)
$Rinput = GUICtrlCreateInput("",70,15,155,20)
GUICtrlCreateLabel("指定日期:",10,50,70,30)
$Rdate = GUICtrlCreateDate(@YEAR&"/"&@MON&"/"&@MDAY,70,45,155,20)
GUICtrlCreateLabel("指定时间:",10,84,70,30)
$Rtime1 = GUICtrlCreateCombo("00",70,80,35,20)
GUICtrlSetData(-1,"01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24")
GUICtrlCreateLabel("时",106,84,15,20)
$Rtime2 = GUICtrlCreateCombo("00",122,80,35,20)
GUICtrlSetData(-1,"01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60")
GUICtrlCreateLabel("分",158,84,15,20)
$Rtime3 = GUICtrlCreateCombo("00",174,80,35,20)
GUICtrlSetData(-1,"01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60")
GUICtrlCreateLabel("秒",210,84,15,20)
GUICtrlCreateLabel("备 注:",10,114,70,30)
$Redit = GUICtrlCreateEdit("",10,135,215,110)
$Rok = GUICtrlCreateButton("确定",50,250,60,25)
$Rcancle = GUICtrlCreateButton("取消",120,250,60,25)
_duqu()
While 1
$Rinput0 = GUICtrlRead($Rinput)
$Rdate0 = GUICtrlRead($Rdate)
$Rtime10 = GUICtrlRead($Rtime1)
$Rtime20 = GUICtrlRead($Rtime2)
$Rtime30 = GUICtrlRead($Rtime3)
$Redit0 = GUICtrlRead($Redit)
$a = '<' & ' '& @YEAR & '年' & @MON & '月' & @MDAY & '日' &' '&'>'& ' ' & @HOUR & ':' & @MIN & ':' & @SEC ;时间
If GUICtrlRead($time) <> $a Then GUICtrlSetData($time,$a)
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
Exit
Case $add
_tianjia()
Case $del
_del()
Case $Rok
_Rok()
Case $Rcancle
_cancle()
EndSwitch
WEnd
Func _tianjia()
GUISetState(@SW_SHOW,$tianjia)
GUISetState(@SW_DISABLE,$bei)
WinSetTrans($bei,"",150)
EndFunc
Func _del()
$aa = GUICtrlRead(GUICtrlRead($GListView))
$bb = StringSplit($aa, '|', 1)
$cc = _GUICtrlListView_GetSelectedIndices($GListView)
$d = MsgBox(1+64,"提示","是否删除"&$bb&"项目?")
If StringLen($d) Then
_GUICtrlListView_DeleteItemsSelected ($GListView)
IniDelete($shuju,"Section",$bb)
ElseIf $d = 2 Then
MsgBox(64,"","你放弃删除选中项!")
EndIf
EndFunc
Func _cancle()
GUICtrlSetData($Rinput,"")
GUICtrlSetData($Rdate,@YEAR&"/"&@MON&"/"&@MDAY)
GUICtrlSetData($Rtime1,"00")
GUICtrlSetData($Rtime2,"00")
GUICtrlSetData($Rtime3,"00")
GUICtrlSetData($Redit,"")
GUISetState(@SW_HIDE,$tianjia)
GUISetState(@SW_ENABLE,$bei)
WinSetTrans($bei,"",250)
EndFunc
Func _Rok()
$hanghao = _GUICtrlListView_GetItemCount($GListView)
;~ $hanghao +=1
If $Rinput0 <> "" And $Rdate0 <> "" And $Rtime10 <> ""And $Rtime20 <> "" And $Rtime30 <> "" And $Redit0 <> "" Then
GUICtrlCreateListViewItem($Rinput0 & "|" & $Rdate0 & "|" & $Rtime10 &":"& $Rtime20 &":"& $Rtime30 & "|" & $Redit0,$GListView)
IniWrite($ShuJu,"Section",$rinput0,$Rinput0 & "|" & $Rdate0 & "|" & $Rtime10 &":"& $Rtime20 &":"& $Rtime30 & "|" & $Redit0)
GUISetState(@SW_HIDE,$tianjia)
GUICtrlSetData($Rinput,"")
GUICtrlSetData($Rdate,@YEAR&"/"&@MON&"/"&@MDAY)
GUICtrlSetData($Rtime1,"00")
GUICtrlSetData($Rtime2,"00")
GUICtrlSetData($Rtime3,"00")
GUICtrlSetData($Redit,"")
GUISetState(@SW_ENABLE,$bei)
WinSetTrans($bei,"",250)
EndIf
EndFunc
Func _duqu()
_GUICtrlListView_DeleteAllItems($GListView)
$var = IniReadSection($ShuJu,"Section")
If Not @error Then
For $i = 1 To $var
GUICtrlCreateListViewItem($var[$i], $GListView)
Next
EndIf
EndFunc是QQ上的你吗``我上次不是给你改好了吗? 不好意思哦。我想知道这样可以不?afan说可以! 哦`我也想知道` 刚刚看了下,这个ini文件以数字递增做关键字很不好,会给删除造成麻烦 afan老大` 我想也知道这样有没有办法删除?
还有那个listview 查找` 然后把数据清空把查找出来的数据显示出来 这样只查找显示查找的数据 本帖最后由 afan 于 2010-6-30 22:12 编辑
将ini格式改一下,将事件名作为关键字,同时删除键值的第一项事件名#include<GUIConstants.au3>
#include <GuiListView.au3>
#include <DateTimeConstants.au3>
Dim $HangHao
$ShuJu = @ScriptDir & "\beiwanglu.ini"
$bei = GUICreate("备忘录", 400, 240)
$GListView = GUICtrlCreateListView(" 事件 | 日期 |指定的时间| 备注 ", 5, 5, 310, 156) ;创建Listview控件,
_GUICtrlListView_SetExtendedListViewStyle($GListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
GUICtrlCreateLabel("现在时刻:", 5, 180, 75, 30)
$time = GUICtrlCreateLabel("", 70, 180, 230, 30)
$add = GUICtrlCreateButton("添加事件", 320, 10, 70, 30)
$del = GUICtrlCreateButton("删除事件", 320, 130, 70, 30)
GUISetState(@SW_SHOW)
;添加窗口
$tianjia = GUICreate("添加事件提醒", 235, 280)
GUICtrlCreateLabel("事件名称:", 10, 20, 70, 30)
$Rinput = GUICtrlCreateInput("", 70, 15, 155, 20)
GUICtrlCreateLabel("指定日期:", 10, 50, 70, 30)
$Rdate = GUICtrlCreateDate(@YEAR & "/" & @MON & "/" & @MDAY, 70, 45, 155, 20)
GUICtrlCreateLabel("指定时间:", 10, 84, 70, 30)
$Rtime1 = GUICtrlCreateCombo("00", 70, 80, 35, 20)
GUICtrlSetData(-1, "01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24")
GUICtrlCreateLabel("时", 106, 84, 15, 20)
$Rtime2 = GUICtrlCreateCombo("00", 122, 80, 35, 20)
GUICtrlSetData(-1, "01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60")
GUICtrlCreateLabel("分", 158, 84, 15, 20)
$Rtime3 = GUICtrlCreateCombo("00", 174, 80, 35, 20)
GUICtrlSetData(-1, "01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60")
GUICtrlCreateLabel("秒", 210, 84, 15, 20)
GUICtrlCreateLabel("备 注:", 10, 114, 70, 30)
$Redit = GUICtrlCreateEdit("", 10, 135, 215, 110)
$Rok = GUICtrlCreateButton("确定", 50, 250, 60, 25)
$Rcancle = GUICtrlCreateButton("取消", 120, 250, 60, 25)
_duqu()
While 1
$Rinput0 = GUICtrlRead($Rinput)
$Rdate0 = GUICtrlRead($Rdate)
$Rtime10 = GUICtrlRead($Rtime1)
$Rtime20 = GUICtrlRead($Rtime2)
$Rtime30 = GUICtrlRead($Rtime3)
$Redit0 = GUICtrlRead($Redit)
$a = '<' & ' ' & @YEAR & '年' & @MON & '月' & @MDAY & '日' & ' ' & '>' & ' ' & @HOUR & ':' & @MIN & ':' & @SEC ;时间
If GUICtrlRead($time) <> $a Then GUICtrlSetData($time, $a)
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
Exit
Case $add
_tianjia()
Case $del
_del()
Case $Rok
_Rok()
Case $Rcancle
_cancle()
EndSwitch
WEnd
Func _tianjia()
GUISetState(@SW_SHOW, $tianjia)
GUISetState(@SW_DISABLE, $bei)
WinSetTrans($bei, "", 150)
EndFunc ;==>_tianjia
Func _del()
$d = MsgBox(1 + 64, "提示", "是否删除选中项目?")
If $d = 1 Then
$key = StringRegExpReplace(_GUICtrlListView_GetItemTextString($GListView), '(.+?)\|.+', '$1')
IniDelete($ShuJu, 'Section', $key)
_GUICtrlListView_DeleteItemsSelected($GListView)
ElseIf $d = 2 Then
MsgBox(64, "", "你放弃删除选中项!")
EndIf
EndFunc ;==>_del
Func _cancle()
GUICtrlSetData($Rinput, "")
GUICtrlSetData($Rdate, @YEAR & "/" & @MON & "/" & @MDAY)
GUICtrlSetData($Rtime1, "00")
GUICtrlSetData($Rtime2, "00")
GUICtrlSetData($Rtime3, "00")
GUICtrlSetData($Redit, "")
GUISetState(@SW_HIDE, $tianjia)
GUISetState(@SW_ENABLE, $bei)
WinSetTrans($bei, "", 250)
EndFunc ;==>_cancle
Func _Rok()
If $Rinput0 <> "" And $Rdate0 <> "" And $Rtime10 <> "" And $Rtime20 <> "" And $Rtime30 <> "" And $Redit0 <> "" Then
GUICtrlCreateListViewItem($Rinput0 & "|" & $Rdate0 & "|" & $Rtime10 & ":" & $Rtime20 & ":" & $Rtime30 & "|" & $Redit0, $GListView)
IniWrite($ShuJu, "Section", $Rinput0, $Rdate0 & "|" & $Rtime10 & ":" & $Rtime20 & ":" & $Rtime30 & "|" & $Redit0)
GUISetState(@SW_HIDE, $tianjia)
GUICtrlSetData($Rinput, "")
GUICtrlSetData($Rdate, @YEAR & "/" & @MON & "/" & @MDAY)
GUICtrlSetData($Rtime1, "00")
GUICtrlSetData($Rtime2, "00")
GUICtrlSetData($Rtime3, "00")
GUICtrlSetData($Redit, "")
GUISetState(@SW_ENABLE, $bei)
WinSetTrans($bei, "", 250)
EndIf
EndFunc ;==>_Rok
Func _duqu()
_GUICtrlListView_DeleteAllItems($GListView)
$var = IniReadSection($ShuJu, "Section")
If Not @error Then
For $i = 1 To $var
GUICtrlCreateListViewItem($var[$i] & '|' & $var[$i], $GListView)
Next
EndIf
EndFunc ;==>_duqu 你也可以删除现有的ini文件,重新添加生成ini文件再测试 afan 高手就是高手`` 你写的代码我都看不懂``我只能做成5楼那样子 回复 12# 410521a
你的都很不错了哦!呵呵! 不过afan还是牛车啊! 厉害、厉害{:face (316):}一下也没看懂~~ {:face (411):}太强了,厉害
页:
[1]
2