Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. int returned as binary no. from CListCtrl::InsertItem

int returned as binary no. from CListCtrl::InsertItem

Scheduled Pinned Locked Moved C / C++ / MFC
c++testingbeta-testingquestion
10 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Manmohan29
    wrote on last edited by
    #1

    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

    L _ 2 Replies Last reply
    0
    • M Manmohan29

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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.

      M C 2 Replies Last reply
      0
      • L Lost User

        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.

        M Offline
        M Offline
        Manmohan29
        wrote on last edited by
        #3

        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

        I L 2 Replies Last reply
        0
        • M Manmohan29

          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

          _ Offline
          _ Offline
          _Superman_
          wrote on last edited by
          #4

          I cannot believe that is happening with this code. You should put a breakpoint at the line with InsertItem and check the value of c. By the way, you need to get rid of the first 2 for statements.

          «_Superman_» I love work. It gives me something to do between weekends.
          Microsoft MVP (Visual C++)

          M 2 Replies Last reply
          0
          • _ _Superman_

            I cannot believe that is happening with this code. You should put a breakpoint at the line with InsertItem and check the value of c. By the way, you need to get rid of the first 2 for statements.

            «_Superman_» I love work. It gives me something to do between weekends.
            Microsoft MVP (Visual C++)

            M Offline
            M Offline
            Manmohan29
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • L Lost User

              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.

              C Offline
              C Offline
              CPallini
              wrote on last edited by
              #6

              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]

              1 Reply Last reply
              0
              • M Manmohan29

                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

                I Offline
                I Offline
                Iain Clarke Warrior Programmer
                wrote on last edited by
                #7

                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/[^]

                M 1 Reply Last reply
                0
                • _ _Superman_

                  I cannot believe that is happening with this code. You should put a breakpoint at the line with InsertItem and check the value of c. By the way, you need to get rid of the first 2 for statements.

                  «_Superman_» I love work. It gives me something to do between weekends.
                  Microsoft MVP (Visual C++)

                  M Offline
                  M Offline
                  Manmohan29
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  • I Iain Clarke Warrior Programmer

                    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/[^]

                    M Offline
                    M Offline
                    Manmohan29
                    wrote on last edited by
                    #9

                    :thumbsup:

                    Future Lies in Present. Manmohan Bishnoi

                    1 Reply Last reply
                    0
                    • M Manmohan29

                      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

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      Manmohan29 wrote:

                      can I get your email ID so that I can ask for programming help.

                      Sorry but 1. I like to decide which questions I answer 2. You will get better and faster help through the forums 3. You could not afford my fees ;) good luck!

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups