Setting selected item for CAknListQueryDialog

Login to reply to this topic.
Thu, 2008-02-07 10:29
Joined: 2007-02-01
Forum posts: 28

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


Thu, 2008-02-07 12:35
Joined: 2007-12-19
Forum posts: 49
Re: Setting selected item for CAknListQueryDialog

Have you checked this constructor ??

IMPORT_C CAknListQueryDialog (CListBoxView::CSelectionIndexArray *aSelectionIndexArray)

Thu, 2008-02-07 14:56
Joined: 2007-02-01
Forum posts: 28
Re: Setting selected item for CAknListQueryDialog

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

Thu, 2008-02-07 15:43
Joined: 2007-12-19
Forum posts: 49
Re: Setting selected item for CAknListQueryDialog

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.

Thu, 2008-02-07 15:56
Joined: 2007-12-19
Forum posts: 49
Re: Setting selected item for CAknListQueryDialog

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 );

Thu, 2008-02-07 17:13
Joined: 2007-02-01
Forum posts: 28
Re: Setting selected item for CAknListQueryDialog


Thanks for that - works a treat!

Dave

  • Login to reply to this topic.