GIDForums  

Go Back   GIDForums > Computer Programming Forums > MS Visual C++ / MFC Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 27-Jul-2004, 05:46
kte kte is offline
New Member
 
Join Date: Jul 2004
Posts: 2
kte is on a distinguished road

MFC CListCtrl, problem selecting item


Hi,
I my program I have a CListCtrl. When the program starts, one of the items in the list control should be selected. It should stay selected until the user selects an other item.
My problem is that I can't get an item to be selected when starting the program. When the user selects an item, the item only is selected until the user clicks elsewhere in the window.

Here is what I do:

CListCtrl round_overview;
round_overview.SubclassDlgItem(IDC_ROUND_LIST,this );

round_overview.SetExtendedStyle(LVS_EX_FULLROWSELE CT | LVS_SHOWSELALWAYS );
round_overview.InsertColumn(0,station, LVCFMT_LEFT,75);
round_overview.InsertColumn(1,round_id, LVCFMT_LEFT,75);
round_overview.InsertColumn(2,emptied_out_of_total , LVCFMT_LEFT,90);

round_overview.InsertItem(round_overview.GetItemCo unt(),"");

round_overview.SetItemText(round_overview.GetItemC ount()-1,0,"test");

round_overview.SetItemState(round_overview.GetItem Count()-1, LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED);


round_overview.EnsureVisible(round_overview.GetIte mCount()-1, FALSE);

What have I done wrong?

Best regards
Kim Therkelsen
  #2  
Old 27-Jul-2004, 07:05
gmn gmn is offline
Junior Member
 
Join Date: Aug 2003
Posts: 33
gmn is on a distinguished road
round_overview.SetCurSel(x); ???

where x is the zero based index number.

At least that works in my app (using the mfc app wizard(exe))
  #3  
Old 27-Jul-2004, 08:08
kte kte is offline
New Member
 
Join Date: Jul 2004
Posts: 2
kte is on a distinguished road
Thank you for your answer,

but I can't get that to work because setCurSel() is not a member of the CListCtrl class.
  #4  
Old 27-Jul-2004, 17:28
JeroenGN JeroenGN is offline
New Member
 
Join Date: Jul 2004
Posts: 4
JeroenGN is on a distinguished road
try the onther from GetCheck (get selected item), the "SetCheck()", wich is a member of CListCtrl

BOOL SetCheck(
int nItem,
BOOL fCheck = TRUE ):


Parameters
nItem
The zero-based index of a list control item.
fCheck
Specifies whether the state image of the item should be visible or not. By default, fCheck is TRUE and the state image is visible. If fCheck is FALSE, it is not visible.


More info on msdn.microsoft.com about SetCheck and the other functions of clistctrl
  #5  
Old 28-Jul-2004, 05:17
gmn gmn is offline
Junior Member
 
Join Date: Aug 2003
Posts: 33
gmn is on a distinguished road
sorry about that, works for me though honest....

get the impression you're doing this the detailed way, which i'm sure is better, but I'm a sucker for the easy option and just created a list box with MSVC++ mfc exe wizard and added a control to it via class wizard. Doing it this way does give you SetCurSel() as a member function. I'm yet to venture out on my own without the good old wizards though....all this win32 stuff looks seriously long winded.
  #6  
Old 01-Feb-2005, 12:15
figashrek figashrek is offline
New Member
 
Join Date: Jan 2005
Posts: 3
figashrek is on a distinguished road
Whats Up.

I had that problem too.

Try round_overview.SetFocus() too keep the focus on the list.

Bye...
 
 

Recent GIDBlogWriting a book by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
CD burner wont burn!! robertli55 Computer Hardware Forum 1 18-Jun-2004 11:53
Yet another CD burner problem: Lite-On LSC-24082K Erwin Computer Hardware Forum 1 22-May-2004 12:28
help on linked lists any1????? nick4 C Programming Language 1 17-May-2004 10:32
Another FX 5600 problem (but with details that might shed light on this) BobDaDuck Computer Hardware Forum 2 16-Apr-2004 08:53
problem with creating class mohammed C++ Forum 1 11-Oct-2003 10:04

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:25.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.