int returned as binary no. from CListCtrl::InsertItem
-
In my MFC program the int 10 (ten) is treated as binary 10 (one & zero) i.e. == 2. So when I insert any item at 10th position then it is inserted at 2nd position. Similarly for 100th item it is inserted at 4th position. My program is a Dialog Based Application. m_ctlDeviceList is control variable for ListCtrl and it is set in Report View.
void CIPMDlg::OnBnClickedBrefreshdevices()
{
// TODO: Add your control notification handler code here
int field0 = 0, field1 = 0, field2 = 0, field3 = 0;
int c=0, nIndex=0;
CString ips = _T("");for (field0 = 192; field0 <= 192; field0++) { for (field1 = 168; field1 <= 168; field1++) { for (field2 = 0; field2 <= 255; field2++) { for (field3 = 0; field3 <= 255; field3++) { ips.Format(\_T("192.168.%u.%u"), field2, field3); nIndex = m\_ctlDeviceList.InsertItem(c, ips); m\_ctlDeviceList.SetItemText(nIndex, 1, \_T("Testing")); c++; } } } }
}
Why is this happening?
Future Lies in Present. Manmohan Bishnoi
-
In my MFC program the int 10 (ten) is treated as binary 10 (one & zero) i.e. == 2. So when I insert any item at 10th position then it is inserted at 2nd position. Similarly for 100th item it is inserted at 4th position. My program is a Dialog Based Application. m_ctlDeviceList is control variable for ListCtrl and it is set in Report View.
void CIPMDlg::OnBnClickedBrefreshdevices()
{
// TODO: Add your control notification handler code here
int field0 = 0, field1 = 0, field2 = 0, field3 = 0;
int c=0, nIndex=0;
CString ips = _T("");for (field0 = 192; field0 <= 192; field0++) { for (field1 = 168; field1 <= 168; field1++) { for (field2 = 0; field2 <= 255; field2++) { for (field3 = 0; field3 <= 255; field3++) { ips.Format(\_T("192.168.%u.%u"), field2, field3); nIndex = m\_ctlDeviceList.InsertItem(c, ips); m\_ctlDeviceList.SetItemText(nIndex, 1, \_T("Testing")); c++; } } } }
}
Why is this happening?
Future Lies in Present. Manmohan Bishnoi
Manmohan29 wrote:
In my MFC program the int 10 (ten) is treated as binary 10 (one & zero) i.e. == 2.
This is definitely not true. I think the problem may be that your ListCtrl is automatically sorting the entries as you add them. So you add "192.168.0.0", "192.168.0.1" etc. Then when you insert "192.168.0.10" it will be inserted in position 2 between "192.168.0.1" and "192.168.0.2". It may be better to ensure that you format the numbers with 3 digits in every case, or turn off the auto sort feature of the ListCtrl.
-
Manmohan29 wrote:
In my MFC program the int 10 (ten) is treated as binary 10 (one & zero) i.e. == 2.
This is definitely not true. I think the problem may be that your ListCtrl is automatically sorting the entries as you add them. So you add "192.168.0.0", "192.168.0.1" etc. Then when you insert "192.168.0.10" it will be inserted in position 2 between "192.168.0.1" and "192.168.0.2". It may be better to ensure that you format the numbers with 3 digits in every case, or turn off the auto sort feature of the ListCtrl.
Bull's Eye. Thanks Richard. can I get your email ID so that I can ask for programming help.
Future Lies in Present. Manmohan Bishnoi
-
In my MFC program the int 10 (ten) is treated as binary 10 (one & zero) i.e. == 2. So when I insert any item at 10th position then it is inserted at 2nd position. Similarly for 100th item it is inserted at 4th position. My program is a Dialog Based Application. m_ctlDeviceList is control variable for ListCtrl and it is set in Report View.
void CIPMDlg::OnBnClickedBrefreshdevices()
{
// TODO: Add your control notification handler code here
int field0 = 0, field1 = 0, field2 = 0, field3 = 0;
int c=0, nIndex=0;
CString ips = _T("");for (field0 = 192; field0 <= 192; field0++) { for (field1 = 168; field1 <= 168; field1++) { for (field2 = 0; field2 <= 255; field2++) { for (field3 = 0; field3 <= 255; field3++) { ips.Format(\_T("192.168.%u.%u"), field2, field3); nIndex = m\_ctlDeviceList.InsertItem(c, ips); m\_ctlDeviceList.SetItemText(nIndex, 1, \_T("Testing")); c++; } } } }
}
Why is this happening?
Future Lies in Present. Manmohan Bishnoi
I cannot believe that is happening with this code. You should put a breakpoint at the line with
InsertItem
and check the value ofc
. By the way, you need to get rid of the first 2for
statements.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) -
I cannot believe that is happening with this code. You should put a breakpoint at the line with
InsertItem
and check the value ofc
. By the way, you need to get rid of the first 2for
statements.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++)Richard MacCutchan solved my problem. The ListCtrl was sorting the items in ascending order. I have set the Sort field to None. Now the program just runs fine.
Future Lies in Present. Manmohan Bishnoi
-
Manmohan29 wrote:
In my MFC program the int 10 (ten) is treated as binary 10 (one & zero) i.e. == 2.
This is definitely not true. I think the problem may be that your ListCtrl is automatically sorting the entries as you add them. So you add "192.168.0.0", "192.168.0.1" etc. Then when you insert "192.168.0.10" it will be inserted in position 2 between "192.168.0.1" and "192.168.0.2". It may be better to ensure that you format the numbers with 3 digits in every case, or turn off the auto sort feature of the ListCtrl.
Thanks Richard. Can I get your bank ID so that I can ask for financial help? :-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Bull's Eye. Thanks Richard. can I get your email ID so that I can ask for programming help.
Future Lies in Present. Manmohan Bishnoi
Manmohan29 wrote:
can I get your email ID so that I can ask for programming help.
This may seem a bit radical, but you could try posting your requests for help on a forum... That way more people will see them. Unless you're offering him money? That'd be different! Iain.
I have now moved to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need contract work done, give me a job! http://cv.imcsoft.co.uk/[^]
-
I cannot believe that is happening with this code. You should put a breakpoint at the line with
InsertItem
and check the value ofc
. By the way, you need to get rid of the first 2for
statements.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++)By the way, you need to get rid of the first 2 for statements. My program(ping application) is just at initial stage. The for loop initializations will be replaced when the values will be taken from the user itself.
Future Lies in Present. Manmohan Bishnoi
-
Manmohan29 wrote:
can I get your email ID so that I can ask for programming help.
This may seem a bit radical, but you could try posting your requests for help on a forum... That way more people will see them. Unless you're offering him money? That'd be different! Iain.
I have now moved to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need contract work done, give me a job! http://cv.imcsoft.co.uk/[^]
:thumbsup:
Future Lies in Present. Manmohan Bishnoi
-
Bull's Eye. Thanks Richard. can I get your email ID so that I can ask for programming help.
Future Lies in Present. Manmohan Bishnoi