April 19, 2024, 05:45:22 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Select Listview in Code

Started by Bruce Peaslee, April 17, 2007, 11:14:42 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Bruce Peaslee

April 17, 2007, 11:14:42 AM Last Edit: April 17, 2007, 11:21:49 AM by peaslee
I can select an item in a list view with code, but it doesn't show as hilighted.


   LV_ITEM lvi;

   lvi.mask = LVIF_STATE;
   lvi.state = LVIS_SELECTED|LVIS_FOCUSED;
   lvi.stateMask = LVIS_SELECTED|LVIS_FOCUSED;

   SendMessage(p_lvwAgenda->m_hwnd,LVM_SETITEMSTATE,0,&lvi);
   msg(NumToStr(p_lvwAgenda->GetCurSel())); // displays "2", so selection happens


Suggestions?

Thanks.

Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Rock Ridge Farm (Larry)

Is there not a separate attribute for highlight? Reversed or something like that?

Bruce Peaslee

Not that I can find. The info I'm using came from MSDN.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Bruce Peaslee

Got it.

Added AWS_TABSTOP to the listvew's style at then set focus.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Rock Ridge Farm (Larry)

Well now that makes lots of sense. Would never have guessed that one.

Bruce Peaslee

I sat staring at the stupid control. I tested the response to the up- and down-arrows -- I knew an item was selected and wanted to see if there was that functionality. No response. Then I clicked in a blank area of the control and the proper item became hilighted. Ahah! Progress. The rest was simple.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Rock Ridge Farm (Larry)

Kool - my kind of programming.

John S

Quote from: peaslee on April 17, 2007, 11:31:23 AM
Got it.
Added AWS_TABSTOP to the listvew's style at then set focus.
can you post a code sample.  I'll using Listview right now and want to see what you're doing.
John Siino, Advanced Engineering Services and Software

Bruce Peaslee

I can't post the whole program as I intend to sell it to the unsuspecting public  :D

Here is what I do for the control creation:

m_dlgAgenda.AddControl(CTLISTVIEW,"",22,25,875,502,AWS_VISIBLE|ALVS_REPORT|AWS_TABSTOP,0x200,AD_LVW_AGENDA);


I think the AWS_TABSTOP is necessary for the control to get the focus. Then I set which item (line) in the list view I want to be selected. This code appears in the OnInitDialog method for the dialog containing the control.

CListView *p_lvwAgenda = GetControl(AD_LVW_AGENDA);
p_lvwAgenda->SetSel(2); // select item 2
SetFocus(AD_LVW_AGENDA);


After determining that the problem appeared to be with the focus, I went back and used the SetSel() method provided by Aurora instead of the Sendmessage technique shown in the previous post.

Is this useful?

Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Bruce Peaslee

I discovered that if you comment out the SetFocus method, the program still works, so I assume all that was needed to fix this problem was the tab stop style constant.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Rock Ridge Farm (Larry)

That kinda makes sense. The set focus would override any previous control.
Is there a specific order in which grouped controls are applied - control precedence?

Bruce Peaslee

Quote from: Rock Ridge Farm (Larry) on April 18, 2007, 09:59:12 AM
Is there a specific order in which grouped controls are applied - control precedence?

If you mean tab order, I believe it follows the sequence of control ID numbers.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Parker

Tab order is in order of when the controls were created, which while usually is the order of the IDs, it doesn't always have to be.