Setting selected item for CAknListQueryDialog
| Thu, 2008-02-07 10:29 | |
|
Hi folks, I have a CAknListQueryDialog that is constructed dynamically. Rather than always having the first item highlighted when the dialog is launched I want to choose which item is selected, thereby providing the user with a valid default selection. Unfortunately I cannot find an API to support this. Please can someone provide me with the correct API? Many thanks Dave |
|






Forum posts: 49
Have you checked this constructor ??
IMPORT_C CAknListQueryDialog (CListBoxView::CSelectionIndexArray *aSelectionIndexArray)
Forum posts: 28
Thanks for the reply, but that doesn't seem to work.
The code is as follows.
// Create a list dialog and pass selectedIndex to get the selected item
TInt selectedIndex = 0;
CAknListQueryDialog* dialog = new(ELeave)CAknListQueryDialog(&selectedIndex);
dialog->PrepareLC(R_QUERY_DIALOG);
//Create flat array from which list is built.
CDesCArrayFlat* items = new(ELeave) CDesCArrayFlat(5);
CleanupStack::PushL(items);
// Add entires to list
items->AppendL (_L("aaaaaaa"));
items->AppendL (_L("b b b b b"));
items->AppendL (_L("cc cc cc"));
// Add items into main list
dialog->SetOwnershipType(ELbmOwnsItemArray);
dialog->SetItemTextArray(items);
CleanupStack::Pop(items);
// Set the selected item
selectedIndex = 3;
// If found, select the default item
TInt answer(dialog->RunLD());
For information, the dialog resource is:
RESOURCE DIALOG r_query_dialog
{
flags = EGeneralQueryFlags;
buttons = r_cba_internal_ok_cancel;
items =
{
DLG_LINE
{
type = EAknCtListQueryControl;
id = EListQueryControl;
control = AVKON_LIST_QUERY_CONTROL
{
listtype = EAknCtSinglePopupMenuListBox;
listbox = LISTBOX
{
flags = EAknListBoxSelectionList;
height = 3;
width = 3;
};
heading = qtn_list_heading;
};
}
};
}
As ever, any assistance gratefully received.
Thanks
Dave
Forum posts: 49
In code above you passed pointer to TInt to constructor and it is not correct. As a parameter you should pass pointer to
CArrayFix<TInt>object which should contain index of item which you want to be selected.Forum posts: 49
Or other and beter way is
CAknListQueryDialog* dialog = new(ELeave)CAknListQueryDialog();
dialog->PrepareLC(R_QUERY_DIALOG);
//Create flat array from which list is built.
CDesCArrayFlat* items = new(ELeave) CDesCArrayFlat(5);
CleanupStack::PushL(items);
// Add entires to list
items->AppendL (_L("aaaaaaa"));
items->AppendL (_L("b b b b b"));
items->AppendL (_L("cc cc cc"));
// Add items into main list
dialog->SetOwnershipType(ELbmOwnsItemArray);
dialog->SetItemTextArray(items);
CleanupStack::Pop(items);
// Set the selected item
TInt selectedIndex = 3;
CEikListBox * listBox = dialog->ListBox();
listBox->SetCurrentItemIndexAndDraw( selectedIndex );
Forum posts: 28
Thanks for that - works a treat!
Dave