Solved

Editing Listbox at runtime 2

Posted on 2004-03-27
3
234 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now