First, please, explain (in words) what you are trying to obtain in this OnClickListCategory method and how and when this method is about to be called.Quote:
Printable View
First, please, explain (in words) what you are trying to obtain in this OnClickListCategory method and how and when this method is about to be called.Quote:
Something like (not tried)
Code:void Cselect_product::OnClickListCategory(NMHDR* pNMHDR, LRESULT* pResult)
{
POSITION p = m_klist.GetFirstSelectedItemPosition();
while (p)
{
int nItemIndex = m_klist.GetNextSelectedItem(p);
TCHAR szBuffer[1024] = {0};
DWORD cchBuf(1023);
LVITEM lvi;
lvi.iItem = nItemIndex;
lvi.iSubItem = 0;
lvi.mask = LVIF_TEXT;
lvi.pszText = szBuffer;
lvi.cchTextMax = cchBuf;
if (m_klist.GetItem(&lvi)) {
//use szBuffer here
} else
OutputDebugString("Error with GetItem\n");
}
*pResult = 0;
}
Read the documentation! https://msdn.microsoft.com/en-us/lib...=vs.85%29.aspx
pszText
Type: LPTSTR
If the structure specifies item attributes, pszText is a pointer to a null-terminated string containing the item text.
So szBuffer will contain the text after a successful call to .getItem()
What List Control notification do you handle?Quote:
Since this is an MFC application then one can use CListCtrl::GetItemText method.
I got the solution using following code means I got the text of selected value.Quote:
void Cselect_product::OnItemchangedListCategory(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
CListCtrl* pListCtrl = (CListCtrl *) GetDlgItem(IDC_ListCategory);
POSITION pos = m_klist.GetFirstSelectedItemPosition ();
if (pos == NULL)
TRACE0 ("No items were selected! \n");
else
{
while (pos)
{
int nItem = m_klist.GetNextSelectedItem (pos);
TRACE1 ("Item %d was selected! \n", nItem);
//you could do your own processing on nItem here
strText = m_klist.GetItemText(nItem, 0);
}
}
*pResult = 0;
}
but list control's view property is set to the List at that time I want all this operation when view property of list control is Report.
1. Again: please, use code tags and avoid multiple empty lines! :mad:
2.Why do you call GetDlgItem? :confused:Quote:
You don't need it at all! Just because you already have the control member variable for this list control: m_klist.
3.Then eithe rset it to Report in the resource editor or change the style to LVS_REPORT. See this thread.Quote:
As Victor stated in post #25, pNMListView and pListCtrl are not required here as you are using m_klist and are thus this is superfluous code. Your effective code is
This assumes that the variable strText is either global or a member of the class - and that m_klist has the correct value.Code:void Cselect_product::OnItemchangedListCategory(NMHDR* pNMHDR, LRESULT* pResult)
{
POSITION pos = m_klist.GetFirstSelectedItemPosition();
if (pos == NULL)
TRACE0("No items were selected! \n");
else
while (pos)
{
int nItem = m_klist.GetNextSelectedItem(pos);
TRACE1("Item %d was selected! \n", nItem);
//you could do your own processing on nItem here
strText = m_klist.GetItemText(nItem, 0);
}
*pResult = 0;
}