Board index » cppbuilder » repost: TCheckListBox->Keep focus, of the selected item..

repost: TCheckListBox->Keep focus, of the selected item..


2004-10-07 06:12:38 AM
cppbuilder66
once again dear builders,
how can i keep the focus if i select an item from a CheckListBox
and than leave the control..?
it should be something like this...
/*****************************************************/
// move item down...
void __fastcall TfrmMainUnit::cmdMove_DownClick(TObject *Sender)
{
if(CheckListBox1->ItemIndex <= CheckListBox1->Items->Count)
{
CheckListBox1->Items->Move(CheckListBox1->ItemIndex,
CheckListBox1->ItemIndex + 1);
}
int itemindex = CheckListBox1->ItemIndex;
CheckListBox1->ItemIndex = itemindex;
CheckListBox1->SetFocus();
}
// move item up...
void __fastcall TfrmMainUnit::cmdMove_UpClick(TObject *Sender)
{
if(CheckListBox1->ItemIndex>0)
{
CheckListBox1->Items->Move(CheckListBox1->ItemIndex,
CheckListBox1->ItemIndex - 1);
}
int itemindex = CheckListBox1->ItemIndex;
CheckListBox1->ItemIndex = itemindex;
CheckListBox1->SetFocus();
}
/*****************************************************/
Oren
 
 

Re:repost: TCheckListBox->Keep focus, of the selected item..

"Oren Halvani" < XXXX@XXXXX.COM >wrote in message
Quote
how can i keep the focus if i select an item from a
CheckListBox and than leave the control..?
You are supposed to set the ItemIndex to the NEW insex, not the CURRENT
index:
void __fastcall TfrmMainUnit::cmdMove_DownClick(TObject *Sender)
{
int index = CheckListBox1->ItemIndex;
if( (index>-1) && (index < (CheckListBox1->Items->Count-1)) )
{
CheckListBox1->Items->Exchange(index, index+1);
CheckListBox1->ItemIndex = (index+1);
}
}
void __fastcall TfrmMainUnit::cmdMove_UpClick(TObject *Sender)
{
int index = CheckListBox1->ItemIndex;
if( index>0 )
{
CheckListBox1->Items->Exchange(index, index-1);
CheckListBox1->ItemIndex = (index-1);
}
}
Gambit
 

Re:repost: TCheckListBox->Keep focus, of the selected item..

Quote

You are supposed to set the ItemIndex to the NEW insex, not the CURRENT
index:

void __fastcall TfrmMainUnit::cmdMove_DownClick(TObject *Sender)
{
int index = CheckListBox1->ItemIndex;
if( (index>-1) && (index < (CheckListBox1->Items->Count-1)) )
{
CheckListBox1->Items->Exchange(index, index+1);
CheckListBox1->ItemIndex = (index+1);
}
}

void __fastcall TfrmMainUnit::cmdMove_UpClick(TObject *Sender)
{
int index = CheckListBox1->ItemIndex;
if( index>0 )
{
CheckListBox1->Items->Exchange(index, index-1);
CheckListBox1->ItemIndex = (index-1);
}
}

Gambit
thanks Remy :-)
Oren
 

{smallsort}