Solved

Editing Listbox at runtime 2

Posted on 2004-03-27
3
247 Views
Last Modified: 2010-04-05
Hey,

I asked before how to edit a listbox at runtime by adding a string "locked" after a SELECTED Listbox item  when a button has been clicked.

Now I want to do the opposite so ...

When I click a button it removes the string "locked" after the SELECTED item.

Cheers,

Computer Programer
0
Comment
Question by:computerprogramer
  • 2
3 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 10697866
procedure TForm1.Button2Click(Sender: TObject);
var
  ind: integer;
begin
  ind := Pos(' Locked',ListBox2.Items[ListBox2.ItemIndex]);
ListBox2.Items[ListBox2.ItemIndex] := Delete(ListBox2.Items[ListBox2.ItemIndex],ind,Length(' Locked')) ;
end;
0
 
LVL 17

Accepted Solution

by:
mokule earned 50 total points
ID: 10697869
or better
procedure TForm1.Button2Click(Sender: TObject);
var
  ind: integer;
begin
  ind := Pos(' Locked',ListBox2.Items[ListBox2.ItemIndex]);
  if ind > 0 then
    ListBox2.Items[ListBox2.ItemIndex] := Delete(ListBox2.Items[ListBox2.ItemIndex],ind,Length(' Locked')) ;
end;
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10701710
procedure TForm1.btnDeleteClick(Sender: TObject);
var
 tmpStr: String;
begin
 //if item is selected
 if ListBox1.ItemIndex <> - 1 then
 begin
  //shut off control painting
  ListBox1.Items.BeginUpdate;
  //get selected item from list
  tmpStr:= ListBox1.Items[ListBox1.ItemIndex];
  //delete string from selected item
  Delete(tmpStr,pos(' - LOCKED',tmpStr),9);
  //post selected item back to list
  ListBox1.Items[ListBox1.ItemIndex]:= tmpStr;
  //turn back on control painting
  ListBox1.Items.EndUpdate;
  end;
end;

procedure TForm1.btnAddClick(Sender: TObject);
var
 tmpStr: String;
begin
 //if item is selected
 if ListBox1.ItemIndex <> - 1 then
 begin
  //shut off control painting
  ListBox1.Items.BeginUpdate;
  //get selected item from list
  tmpStr:= ListBox1.Items[ListBox1.ItemIndex];
  tmpStr:= tmpStr + ' - LOCKED';
  //post selected item back to list
  ListBox1.Items[ListBox1.ItemIndex]:= tmpStr;
  //turn back on control painting
  ListBox1.Items.EndUpdate;
  end;
end;
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question