search a list control
-
Hi, GetItem has the declaration like this:BOOL GetItem(LVITEM* pItem) const; So it can't accept a int type parameter. besides, it return a BOOL value; I think you must misunderstand the function.
-
Use FindItem() to get the index of the list control you want. int FindItem(LVFINDINFO* pFindInfo, int nStart = -1) const; ipAdd.GetAddress(m_M1, m_M2, m_M3, m_M4); LVFINDINFO temp; temp.flags = LVFI_PARTIAL|LVFI_STRING; _stprintf_s(temp.psz, _T("%d : %d : %d : %d"), m_M1, m_M2, m_M3, m_M4); //I'm not sure if this would work int i = ipList.FindItem(&temp);
-
Use FindItem() to get the index of the list control you want. int FindItem(LVFINDINFO* pFindInfo, int nStart = -1) const; ipAdd.GetAddress(m_M1, m_M2, m_M3, m_M4); LVFINDINFO temp; temp.flags = LVFI_PARTIAL|LVFI_STRING; _stprintf_s(temp.psz, _T("%d : %d : %d : %d"), m_M1, m_M2, m_M3, m_M4); //I'm not sure if this would work int i = ipList.FindItem(&temp);
-
In addition to the above comment, you can use the
FindItem()
function of list control directly. No need to loop. -
this code is giving error ----
_stprintf_s(temp.psz, _T("%d : %d : %d : %d"), m_M1, m_M2, m_M3, m_M4);
error
error C2664: 'int swprintf_s(wchar_t *,size_t,const wchar_t *,...)' : cannot convert parameter 1 from 'LPCWSTR' to 'wchar_t *'
I'm sorry for that. You can try the code below. wchar_t ss[100]; _stprintf_s(ss, _T("%d : %d : %d : %d"), m_M1, m_M2, m_M3, m_M4); //I'm not sure if this would work temp.psz = ss; Hope it can run.
-
I'm sorry for that. You can try the code below. wchar_t ss[100]; _stprintf_s(ss, _T("%d : %d : %d : %d"), m_M1, m_M2, m_M3, m_M4); //I'm not sure if this would work temp.psz = ss; Hope it can run.
-
thanks, it is working now. also, in the second list control in application, there is check box in first column for ach item. please tell me how to get the items which are checked ?
But I know you can add 'LVN_ITEMCHANGED' Message handling functions for the CListCtrl, when checkbox's state is changed, the function would be activated, and you can check if the checkbox is be selected in the Message handling functions.
-
But I know you can add 'LVN_ITEMCHANGED' Message handling functions for the CListCtrl, when checkbox's state is changed, the function would be activated, and you can check if the checkbox is be selected in the Message handling functions.
thanks. i am facing a new problem. i am trying to save the items of list control which are checked to a text file. here is the code ---
TCHAR ff\[100\] = {0}; CFile srvc; srvc.Open(\_T("c:\\\\srvc.txt"), CFile::modeCreate|CFile::modeReadWrite); for (int nItem = 0; nItem < srvcList.GetItemCount(); nItem++) { if (srvcList.GetCheck(nItem)) { srvcList.GetItemText(nItem, 0, (LPTSTR)ff, 98); wcscat\_s(ff, L"\\n"); srvc.SeekToEnd(); srvc.Write(ff, 100); ZeroMemory(ff, 100); } }
the content of the file is not right ---
A e L o o k u p S v c
þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþA p p H o s t S v c
þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþA V P
þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþB F E
þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþB I T S
þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþthere is extra space between each letter and the symble 'þ'. there is also no new line even with the use of '\n'.
modified on Saturday, July 18, 2009 11:05 PM
-
thanks. i am facing a new problem. i am trying to save the items of list control which are checked to a text file. here is the code ---
TCHAR ff\[100\] = {0}; CFile srvc; srvc.Open(\_T("c:\\\\srvc.txt"), CFile::modeCreate|CFile::modeReadWrite); for (int nItem = 0; nItem < srvcList.GetItemCount(); nItem++) { if (srvcList.GetCheck(nItem)) { srvcList.GetItemText(nItem, 0, (LPTSTR)ff, 98); wcscat\_s(ff, L"\\n"); srvc.SeekToEnd(); srvc.Write(ff, 100); ZeroMemory(ff, 100); } }
the content of the file is not right ---
A e L o o k u p S v c
þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþA p p H o s t S v c
þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþA V P
þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþB F E
þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþB I T S
þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþthere is extra space between each letter and the symble 'þ'. there is also no new line even with the use of '\n'.
modified on Saturday, July 18, 2009 11:05 PM
Hi. I use " CString temp(ff); srvc.Write(ff, 2 * temp.GetLength() - 1); " instead of your "srvc.Write(ff, 100);", and it's works OK in my computer. Maybe you can try it, but it must not be a good solution. If it couldn't work, tell me and I would try to find another solution.
-
thanks. i am facing a new problem. i am trying to save the items of list control which are checked to a text file. here is the code ---
TCHAR ff\[100\] = {0}; CFile srvc; srvc.Open(\_T("c:\\\\srvc.txt"), CFile::modeCreate|CFile::modeReadWrite); for (int nItem = 0; nItem < srvcList.GetItemCount(); nItem++) { if (srvcList.GetCheck(nItem)) { srvcList.GetItemText(nItem, 0, (LPTSTR)ff, 98); wcscat\_s(ff, L"\\n"); srvc.SeekToEnd(); srvc.Write(ff, 100); ZeroMemory(ff, 100); } }
the content of the file is not right ---
A e L o o k u p S v c
þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþA p p H o s t S v c
þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþA V P
þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþB F E
þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþB I T S
þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþthere is extra space between each letter and the symble 'þ'. there is also no new line even with the use of '\n'.
modified on Saturday, July 18, 2009 11:05 PM
srvc.Write(ff, 2 * lstrlen(ff) - 1); This can work in my computer too, maybe it's better than the last one I gave you.
-
Hi. I use " CString temp(ff); srvc.Write(ff, 2 * temp.GetLength() - 1); " instead of your "srvc.Write(ff, 100);", and it's works OK in my computer. Maybe you can try it, but it must not be a good solution. If it couldn't work, tell me and I would try to find another solution.
-
srvc.Write(ff, 2 * lstrlen(ff) - 1); This can work in my computer too, maybe it's better than the last one I gave you.
-
My OS is winows XP. And if I view the text by Notepad.exe, it's the same as you. But if I use anothor software to view the text, it just be OK.
-
wcscat_s(ff, L"\n"); Em, try to replace the code by 1. wcscat_s(ff, L"\r\n"); 2. wcscat_s(ff, L"\r"); 3. wcscat_s(ff, L"\n\r");
-
wcscat_s(ff, L"\n"); Em, try to replace the code by 1. wcscat_s(ff, L"\r\n"); 2. wcscat_s(ff, L"\r"); 3. wcscat_s(ff, L"\n\r");
i do some changes ----
for (int nItem = 0; nItem < srvcList.GetItemCount(); nItem++)
{
if (srvcList.GetCheck(nItem))
{
srvcList.GetItemText(nItem, 0, (LPTSTR)ff, 98);
//wcscat_s(ff, L"\r\n");
srvc.SeekToEnd();
int i = 2 * lstrlen(ff) - 2;
int j = 0;
while(i)
{
srvc.Write(&ff[j], 1);
i--;
j++;
}
}
}the content is ---
AVP BFE BITS
if i use wcscat_s(ff, L"\r\n"), then
AVP
þþþBFE
þþþBITS
þþþþthis text file will be used by other program, therefore cant compromise with it.
-
i do some changes ----
for (int nItem = 0; nItem < srvcList.GetItemCount(); nItem++)
{
if (srvcList.GetCheck(nItem))
{
srvcList.GetItemText(nItem, 0, (LPTSTR)ff, 98);
//wcscat_s(ff, L"\r\n");
srvc.SeekToEnd();
int i = 2 * lstrlen(ff) - 2;
int j = 0;
while(i)
{
srvc.Write(&ff[j], 1);
i--;
j++;
}
}
}the content is ---
AVP BFE BITS
if i use wcscat_s(ff, L"\r\n"), then
AVP
þþþBFE
þþþBITS
þþþþthis text file will be used by other program, therefore cant compromise with it.
It looks inefficient :)
-
It looks inefficient :)
-
still there is a problem, there is no new line. i want the content of the text file like this ----- AVP BFE BITS
You can try veiwing the text in Edit Plus or other text edit software.
-
still there is a problem, there is no new line. i want the content of the text file like this ----- AVP BFE BITS
You can try this, open the "srvc.txt", and select all text, and copy them, and open anthor TextEditor(Edit Plus), and paste. If still there is no new line, then I have no ideas. It's seems that Microsoft define a new line as '\r\n', while in Unix it's '\n'.
-
You can try this, open the "srvc.txt", and select all text, and copy them, and open anthor TextEditor(Edit Plus), and paste. If still there is no new line, then I have no ideas. It's seems that Microsoft define a new line as '\r\n', while in Unix it's '\n'.
thanks for all the support. finally it is done. the code is not that good ---
TCHAR ff\[100\] = {0}; CStdioFile srvc; srvc.Open(\_T("c:\\\\srvc.txt"), CFile::modeCreate|CFile::modeReadWrite); for (int nItem = 0; nItem < srvcList.GetItemCount(); nItem++) { if (srvcList.GetCheck(nItem)) { srvcList.GetItemText(nItem, 0, (LPTSTR)ff, 100); int i = 2 \* lstrlen(ff) - 2; srvc.SeekToEnd(); int j = 0; while(i) { srvc.Write(&ff\[j++\], 1); --i; } ZeroMemory(ff, 100); srvc.SeekToEnd(); srvc.Write("\\n", 1); } }
output is ---
Audiosrv
AVP
BFE
BITSalso please tell me that is there a way due to which edit box control can take only numeric values and with in a bound, say 1 to 1000 only ???
modified on Sunday, July 19, 2009 5:19 PM