IonicWind Software

Aurora Compiler => GUI => Topic started by: Bruce Peaslee on April 17, 2007, 11:14:42 AM

Title: Select Listview in Code
Post by: Bruce Peaslee on April 17, 2007, 11:14:42 AM
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.

Title: Re: Select Listview in Code
Post by: Rock Ridge Farm (Larry) on April 17, 2007, 11:21:47 AM
Is there not a separate attribute for highlight? Reversed or something like that?
Title: Re: Select Listview in Code
Post by: Bruce Peaslee on April 17, 2007, 11:23:55 AM
Not that I can find. The info I'm using came from MSDN.
Title: Re: Select Listview in Code
Post by: Bruce Peaslee on April 17, 2007, 11:31:23 AM
Got it.

Added AWS_TABSTOP to the listvew's style at then set focus.
Title: Re: Select Listview in Code
Post by: Rock Ridge Farm (Larry) on April 17, 2007, 11:40:32 AM
Well now that makes lots of sense. Would never have guessed that one.
Title: Re: Select Listview in Code
Post by: Bruce Peaslee on April 17, 2007, 12:02:25 PM
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.
Title: Re: Select Listview in Code
Post by: Rock Ridge Farm (Larry) on April 17, 2007, 12:56:11 PM
Kool - my kind of programming.
Title: Re: Select Listview in Code
Post by: John S on April 17, 2007, 01:38:34 PM
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.
Title: Re: Select Listview in Code
Post by: Bruce Peaslee on April 17, 2007, 02:41:20 PM
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?

Title: Re: Select Listview in Code
Post by: Bruce Peaslee on April 18, 2007, 09:27:29 AM
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.
Title: Re: Select Listview in Code
Post by: Rock Ridge Farm (Larry) on April 18, 2007, 09:59:12 AM
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?
Title: Re: Select Listview in Code
Post by: Bruce Peaslee on April 18, 2007, 10:14:59 AM
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.
Title: Re: Select Listview in Code
Post by: Parker on April 20, 2007, 09:07:47 AM
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.