BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to move the selecttion of the items (ListBox) via the UP

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
Oren Halvani
Guest





PostPosted: Wed Sep 13, 2006 10:03 pm    Post subject: How to move the selecttion of the items (ListBox) via the UP Reply with quote



dear builders,

i'm working with a old BCB-project (BCB 3)
i have there a form with a ListBox on it which
includes some items...

But this ListBox doesn't support to move the selection
of the items via the UP/DOWN arrow keys like in modern
applications...

can someone drop me a hint how to enable this functionality...?


Oren


/************************************************/
void __fastcall TfrmMainUnit::ListBoxKeyDown(TObject *Sender, WORD &Key,TShiftState Shift)
{
/******* Selektieren der Items mit Pfeiltasten... *************/

if(Key == VK_UP)
{
// ShowMessage("VK_UP works...");
}

Key = 0;
}
Back to top
JD
Guest





PostPosted: Wed Sep 13, 2006 11:10 pm    Post subject: Re: How to move the selecttion of the items (ListBox) via th Reply with quote



"Oren Halvani" <Spam (AT) halvani (DOT) de> wrote:
Quote:

[...] how to enable this functionality...?

Set the form's KeyPreview to true and add an OnKeyDown(Press?)
event to the form. If VK_DOWN or VK_UP is detected if the
form's ActiveControl is the TListBox, send it an appropriate
scroll message. You can also just set the top item to force a
scroll. You also might want to change the selection as well.

~ JD
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Sep 13, 2006 11:27 pm    Post subject: Re: How to move the selecttion of the items (ListBox) via th Reply with quote



"Oren Halvani" <Spam (AT) halvani (DOT) de> wrote in message
news:450839f8 (AT) newsgroups (DOT) borland.com...

Quote:
But this ListBox doesn't support to move the selection
of the items via the UP/DOWN arrow keys like in modern
applications...

That is because what you are asking for is not a feature of the standard
ListBox control to begin with. You have to implement it in your own code.

Quote:
can someone drop me a hint how to enable this functionality...?

Here is the code I use (except that I use buttons instead of key presses):

void __fastcall TSettingsForm::CheckItemIndex(int index)
{
UpButton->Enabled = (index > 0);
DownButton->Enabled = ((index > -1) && (index <
(ListBox->Items->Count-1)));
}

void __fastcall TSettingsForm::UpButtonClick(TObject *Sender)
{
int index = ListBox->ItemIndex;
ListBox->Items->Exchange(index-1, index);

--index;
ListBox->ItemIndex = index;
CheckItemIndex(index);
}

void __fastcall TSettingsForm::DownButtonClick(TObject *Sender)
{
int index = ListBox->ItemIndex;
ListBox->Items->Exchange(index, index+1);

++index;
ListBox->ItemIndex = index;
CheckItemIndex(index);
}


Gambit
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Sep 13, 2006 11:28 pm    Post subject: Re: How to move the selecttion of the items (ListBox) via th Reply with quote

"JD" <nospam (AT) nospam (DOT) com> wrote in message
news:4508499d$1 (AT) newsgroups (DOT) borland.com...

Quote:
If VK_DOWN or VK_UP is detected if the form's ActiveControl
is the TListBox, send it an appropriate scroll message. You can
also just set the top item to force a scroll.

I think that you are thinking of something else. Scrolling has nothing to
do with moving items around.


Gambit
Back to top
Oren Halvani
Guest





PostPosted: Thu Sep 14, 2006 1:35 am    Post subject: Re: How to move the selecttion of the items (ListBox) via th Reply with quote

Sorry guys,

i didn't explained my problem very well, so you don't understand
what i actually mean...

all i want, is just to select items from the ListBox if
the user clicks on the UP / DOWN keys...(what actually is possible
by default in a ListBox...)

BUT my problem is, that i'm catching keys in the OnKeyDown ( )
and so i have to implement the "default functionality" to go through all
items if a user is clicking the UP / DOW keys...


My OnKeyDown () looks like that:
----------------------------------------------------------------------------------------

void __fastcall TfrmMainUnit::ListBoxKeyDown(TObject *Sender, WORD &Key,TShiftState Shift)
{
if(Key == VK_DELETE || Key == VK_BACK) cmdRemoveFileClick(0);

if(Shift.Contains(ssCtrl))
{
if(Key == 'A') FileBox->Selected[-1] = true; // Select all items...
}

/******* Select the item that has been clicked via UP / DOWN *************/

if(Key == VK_UP) // WHAT TO IMPLEMENT HERE ??

Key = 0;
}
----------------------------------------------------------------------------------------

cam someone drop me a hint...?


Oren
Back to top
DreamChaser
Guest





PostPosted: Sat Mar 03, 2007 9:11 am    Post subject: Re: How to move the selecttion of the items (ListBox) via th Reply with quote

Quote:

/******* Select the item that has been clicked via UP / DOWN *************/

if(Key == VK_UP) // WHAT TO IMPLEMENT HERE ??

Key = 0;
}
----------------------------------------------------------------------------------------

ListBox->ItemIndex = ListBox->ItemIndex - 1;

You will need to check if ItemIndex is already at 0 (zero - The top) and
either ignore or loop to the bottom (i.e. ItemIndex = Items->Count - 1)

DC
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.