 |
|
 |
Why not this way? <code> int count = mList.GetSelectedCount(); if ( 0 == count) return; int item = mList.GetSelectionMark(); if (-1 == item) return; </code>
|
|
|
|
 |
|
 |
i came up with this, tested in small icon and report views with LVS_SHOWSELALWAYS
use the class wizard to handle LVN_ITEMCHANGED
void CMyDlg::OnItemchangedList1(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
// normally, when a new item is selected, the old item loses focus followed by 'selected' status
// so if an item is losing 'selected' status BUT still has focus, then
// the 'white area' was clicked (..or 'selected' status was programatically taken away)
if ((pNMListView->uOldState == LVIS_SELECTED) && (pNMListView->uNewState == 0))
if (m_ctrlList.GetItemState(pNMListView->iItem, LVIS_FOCUSED))
m_ctrlList.SetItemState(pNMListView->iItem, LVIS_SELECTED, LVIS_SELECTED);
*pResult = 0;
}
|
|
|
|
 |
|
 |
Don't forget NM_DBLCLICK and NM_RDBLCLICK.
|
|
|
|
 |
|
 |
After the additional virtual data mode was made into the CListCtrl it is SO complete, quick and good at it gets...
===================
Lars [Large] Werner
lars@werner.no
===================
|
|
|
|
 |
|
 |
How about a SetCurSel() too?
To set the first item selected I've done this:
// m_ctrlList is my member variable for my CListCtrl
m_ctrlList.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED | LVIS_FOCUSED);
It works... but now to move the selection down through the list I have to press the cursor down key twice to start moving. Anyone know what else I need to do?
|
|
|
|
 |
|
 |
Ok... I've got it!
m_ctrlList.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
m_ctrlList.SetItemState(0, LVIS_FOCUSED, LVIS_FOCUSED);
|
|
|
|
 |
|
 |
I have done exactly what you have but for some reason my item is not highlighted. It is definately selected because I can retrieve the selected item.
Any ideas why it's not highlighting?
|
|
|
|
 |
|
 |
I looked a current project that is working an my item is highlighted. I see that I set the focus to the control like this:
// set focus to selection list
m_ctrlAccViewSelList.SetFocus();
// set the first item as selected
m_ctrlAccViewSelList.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
m_ctrlAccViewSelList.SetItemState(0, LVIS_FOCUSED, LVIS_FOCUSED);
Could it be that your control does not have focus?
|
|
|
|
 |
|
 |
Nope. That wasn't it in my case.
------- signature starts
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
"You won't like me when I'm angry..." - Dr. Bruce Banner
Please review the Legal Disclaimer in my bio.
------- signature ends
|
|
|
|
 |
|
 |
try this:
SetItemState(nItemNum, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED);
|
|
|
|
 |
|
 |
I'm using TEXT_CALLBACK (OnGetDispInfo()),
and I can't make the list control show more
than 260 characters...
I've tried to experiment with cchTextMax, but it doesn't
seem to helt.
Is this also a stupid thing in CListCtrl, or is it just my
lack of skill?
Anyone??
|
|
|
|
 |
|
 |
Did anyone ever figure out how to get more than 259 / 260 characters?
Thanks so much.
Best Regards,
Andrew Bond
|
|
|
|
 |
|
 |
No answers yet on this issue, so I will insist.
CTreeCtrl has a display limit of aprox. 260 chars per item.
Anyone knows of how to bypass this limit or create a multiline item?
Be well, people
|
|
|
|
 |
|
 |
Try passing the address of your text buffer instead of copying text to TVITEM.
|
|
|
|
 |
|
 |
Tried that, didn't work.
Best way I coould overcome was to write data to multiple lines....
|
|
|
|
 |
|
 |
What about selecting via the keyboard? Like using the cursor keys to move through the list and selecting with the space bar?
I even thought I might use the MN_RETURN message to select via the ENTER key... but that didn't seem to fire.
|
|
|
|
 |
|
 |
I used the wizard to add an OnChar() member function in my view and did this:
LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR; // wizard wrote this line
// TODO: Add your control notification handler code here
if (pLVKeyDow->wVKey == VK_SPACE)
{
// do what ever
}
|
|
|
|
 |
|
 |
The wizard does not let you add a WM_CHAR notification message for a CListCtrl control to the dialog box class. You can add a WM_CHAR message handler, but that is for keystrokes handled by the dialog box (which is probably none since the dialog controls nab all of them). I tried adding a notification entry manually for the WM_CHAR message, but it did not work.
There is a LVN_KEYDOWN notification from CListCtrl that you can get. Unfortunately, you receive the notification before the list item selection changes, so if you ask the control for the selected item's index, you may get the wrong index.
I am using Visual C++ 6. Things may be different in .NET, of course.
|
|
|
|
 |
|
 |
The LVN_ITEMCHANGED notification may be the best way to go if you want to respond to the user selecting new items using either the mouse or the keyboard. This notification will be sent if the user single clicks, double clicks, right or left mouse button; or if the user presses the up and down arrow keys and changes the highlighted item.
|
|
|
|
 |
|
 |
Anyone figured out how to get reasonably well fitting column width for the data shown in a listctrl. especially if the field len of the data is variable
|
|
|
|
 |
|
 |
I call my AdjustColums() function, particularly when listing file paths. It will adjust to the length of the longest string. If you are using normal path strings (e.g., uppercase) use tm.tmMaxCharWidth instead of tm.tmAveCharWidth. void CMenuView::AdjustColumns() { CDC* pDC = GetDC(); TEXTMETRIC tm; pDC->GetTextMetrics(&tm); CString s; int nWidth = 0; // get the max length of the strings in column 1 for(int i = 0; i < GetListCtrl().GetItemCount(); i++) { s = GetListCtrl().GetItemText(i, 0); if( s.GetLength() > nWidth ) nWidth = s.GetLength(); } // addjust the filename column width GetListCtrl().SetColumnWidth(0, nWidth * tm.tmAveCharWidth); nWidth = 0; // get the max length of the strings in column 2 for(int j = 0; j < GetListCtrl().GetItemCount(); j++) { s = GetListCtrl().GetItemText(j, 1); if( s.GetLength() > nWidth ) nWidth = s.GetLength(); } // adjust the path column width GetListCtrl().SetColumnWidth(1, nWidth * tm.tmAveCharWidth); }
Mark
|
|
|
|
 |
|
 |
there is a 1 or 2 line way of doing this. i don't know what it is off hand, but i've seen it
you know how if you double click the column header seperator it will auto adjust the width of that column? the code i saw basically fired that event.
|
|
|
|
 |
|
 |
>Now, if you click the a blank area under the last item in the list control, what >happens? I'll tell you what happens - the highlight bar goes away.
Why don't you just set the style LVS_SHOWSELALWAYS ?
|
|
|
|
 |
|
 |
I already am. I think there's a bug in the CListCtrl.
------- signature starts
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
Please review the Legal Disclaimer in my bio.
------- signature ends
|
|
|
|
 |
|
 |
Man, you've hardly shown the tip of the iceberg.
One of the most stupid things in list control is the inability to format the text in the first (that is at index zero) column - it stays left. And then, you can find on MSDN the work around - add a dummy column first, and then remove(!) it - the formatting of the remaining columns is preserved and you get the first column formatted any way you want.
I wonder what genius has thought out that "feature"!
<center> </center>
|
|
|
|
 |