|
|
Delete The Select Item From The List - ListView Box: 1. Open Borland C++ Builder. 2. Place a Button on the form. 3. Place a Label on the form. 4. Place a ListView on the form and make its width at least 300 and height at least 150 with scrollbars. 5. Go to the Object Inspector and change the ViewStyle of ListView1 to vsReport and add one colomn. 6. Double click Button1. 7. Type the following red code in the Button1Click function: //This is what the Button1Click function should look like: void __fastcall TForm1::Button1Click(TObject *Sender) { TListItem *LST; char tmp_str[256]; char tmpstr[256]; char szFullPath[256]; AnsiString cookie, gCaption; WIN32_FIND_DATA w32; BOOL finding = TRUE; int cntr = 0; SHFILEINFO info; ListView1->Column[0]->Width = Form1->ListView1->Width; SHGetSpecialFolderPath(NULL, tmp_str, CSIDL_COOKIES, FALSE); ListView1->Items->Clear(); strcpy(tmpstr, tmp_str); strcat(tmpstr, "\\"); SetCurrentDirectory(tmpstr); strcat(tmpstr, "*"); HANDLE hFile = FindFirstFile(tmpstr, &w32); while(finding) { if(!(w32.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { GetFullPathName(w32.cFileName, MAX_PATH, szFullPath, NULL); cookie = w32.cFileName; if(cookie.UpperCase() != "INDEX.DAT") { if(cntr == 0) cntr = 1; LST = ListView1->Items->Add(); LST->Caption = w32.cFileName; gCaption = "Internet Cookies "; gCaption += cntr++; gCaption += " Item(s) Found"; Form1->ListView1->Column[0]->Caption = gCaption; } } finding = FindNextFile(hFile, &w32); } } //--------------------------------------------------------------------------- 8. Now select ListView1 and go to the Object Inspector, click the Events tab and add an OnChange function to the program. 9. Type the following red code in the ListView1Change function: void __fastcall TForm1::ListView1Change(TObject *Sender, TListItem *Item, TItemChange Change) { if(ListView1->Selected) { Label1->Caption = ListView1->Items->Item[ListView1->Selected->Index]->Caption; } } //--------------------------------------------------------------------------- 10. Add nonother button to the form. 11. Double click Button2 12. Type the following red code in the Button2Click function void __fastcall TForm1::Button2Click(TObject *Sender) { if(ListView1->Selected) { ListView1->Items->Item[ListView1->Selected->Index]->Delete(); } } //--------------------------------------------------------------------------- 13. Run the program, click the button. ListView1 will be filled with a list of all the Internet Explorer or AOL cookies on your computer. Click one of the items in the list and Label1 will display the selected item. Now click Button2 and the selected item will be deleted from the list. |