Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting multiple items

Status
Not open for further replies.

801119

Programmer
Apr 10, 2000
311
0
0
SE
Hey all...!!

How do I delete items in a TListBox when multiple items are selected?? Martin G Broman
mgb_svea@thevortex.com

DWS - Alpha Whitin Dead Wolf Society
 
The only way (I suppose):
//--------------------------------------------------
void deleteItems()
{
int* sel = new int[ListBox1->Items->Count];
int j = 0;

for(int k = 0;k < ListBox1->Items->Count;k++)
if(ListBox1->Selected[k])
sel[j++] = k;

while(j)
ListBox1->Items->Delete(sel[--j]);

delete[] sel;
}
//----------------------------------------------------
 
Thanks for the idée...

Though confused as I was over your code (for a minute) I did something like that; if works the same way I supose:

for( int x = 0 ; x < ListBox1->Items->Count ; x++)
if( ListBox1->Selected[x] )
ListBox1->Items->Delete[x];

Thanks again for the idée!! Martin G Broman
mgb_svea@thevortex.com

DWS - Alpha Whitin Dead Wolf Society
 
Greetings!

Another way(I hope it will work!) ;-)

void DeleteItems()
{
for(i = ListBox1->Items->Count - 1; i >= 0; i++)
if(ListBox1->Selected)
ListBox1->Items->Delete;
}

Or this ...

{
for(i = 0; i < ListBox1->Items->Count; i++)
if(ListBox1->Selected)
break;
for(j = i; j < ListBox1->Items->Count; j++)
if(ListBox1->Selected[j])
ListBox1->Items->Delete[j];
else
break;
}
 
Greetings!

Oh, sorry, in this string
for(i = ListBox1->Items->Count - 1; i >= 0; i++) ,
it should read so...
for(i = ListBox1->Items->Count - 1; i >= 0; i--) ,


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top