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. search a list control

search a list control

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
40 Posts 3 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.
  • R rahuljin

    thanks, both the problems are solved.

    BYTE m\_M1, m\_M2, m\_M3, m\_M4;
        TCHAR ss\[50\] = {0};
    UpdateData();
    int i = -1;
    LVFINDINFO temp;
    
        ipAdd.GetAddress(m\_M1, m\_M2, m\_M3, m\_M4);
    temp.flags = LVFI\_PARTIAL|LVFI\_STRING;
    
    \_stprintf\_s(ss, \_T("%d.%d.%d.%d"), m\_M1, m\_M2, m\_M3, m\_M4);
    temp.psz = ss;
    i = ipList.FindItem(&temp);
     
    if(radBut1->GetState())
    {
    	if(m\_M1 && (i == -1 || lstrcmp(ipList.GetItemText(i, 0), temp.psz) != 0) )
    	{
    		ipList.InsertItem(s++, (LPCTSTR)ss);
    		ipAdd.ClearAddress();
    	}
    }
    
    else if(radBut2->GetState())
    {
    
    	if (i != -1 && lstrcmp(ipList.GetItemText(i, 0), temp.psz) == 0)
    	{
    		ipList.DeleteItem(i);
    		s--;
    	}
    
    	else 
    		MessageBox((LPCTSTR)L"Error: Address not found", (LPCTSTR)L"Delete Address", MB\_ICONWARNING | MB\_OK);
    
    
    	ipAdd.ClearAddress();
    
    		
    }
    
    C Offline
    C Offline
    carter2000
    wrote on last edited by
    #31

    I think your code still has some problems. Consider the situation below: There are two items in CListCtrl. 111.111.111.111 111.111.111.11 And you enter 111.111.111.11 to insert the new item, see what happen. If I am right, it will insert successfully!!That may not be what you want.

    R 1 Reply Last reply
    0
    • C carter2000

      BYTE m_M1, m_M2, m_M3, m_M4;
      TCHAR ss[50] = {0};
      UpdateData();
      ipAdd.GetAddress(m_M1, m_M2, m_M3, m_M4);
      _stprintf_s(ss, _T("%d.%d.%d.%d"), m_M1, m_M2, m_M3, m_M4);
      int compare;
      for (int i = 0; i < ipList.GetItemCount(), ++i)
      {
      compare = lstrcmp(ss, ipList.GetItemText(i));
      if(radBut1->GetState())
      {
      if(m_M1 && m_M2 && m_M3 && m_M4 && compare != 0)
      {
      ipList.InsertItem(s++, (LPCTSTR)ss);
      ipAdd.ClearAddress();
      }
      }
      else if(radBut2->GetState())
      {
      if(compare == 0)
      ipList.DeleteItem(i);
      else
      MessageBox((LPCTSTR)L"Error: Address not found", (LPCTSTR)L"Delete Address", MB_ICONWARNING | MB_OK);
      ipAdd.ClearAddress();
      }
      }

      This is the final version. :)

      R Offline
      R Offline
      rahuljin
      wrote on last edited by
      #32

      got another solution ---

      temp.flags = LVFI_STRING;

      and everything becomes right.

      modified on Monday, July 20, 2009 5:46 AM

      C 1 Reply Last reply
      0
      • R rahuljin

        got another solution ---

        temp.flags = LVFI_STRING;

        and everything becomes right.

        modified on Monday, July 20, 2009 5:46 AM

        C Offline
        C Offline
        carter2000
        wrote on last edited by
        #33

        You are right. :)

        R 1 Reply Last reply
        0
        • C carter2000

          I think your code still has some problems. Consider the situation below: There are two items in CListCtrl. 111.111.111.111 111.111.111.11 And you enter 111.111.111.11 to insert the new item, see what happen. If I am right, it will insert successfully!!That may not be what you want.

          R Offline
          R Offline
          rahuljin
          wrote on last edited by
          #34

          in that case, 'i' will not be -1 and lstrcmp(ipList.GetItemText(i, 0), temp.psz) will be equal to zero because the item text and temp.psz will be same.

          C 1 Reply Last reply
          0
          • R rahuljin

            in that case, 'i' will not be -1 and lstrcmp(ipList.GetItemText(i, 0), temp.psz) will be equal to zero because the item text and temp.psz will be same.

            C Offline
            C Offline
            carter2000
            wrote on last edited by
            #35

            Before you changed the "temp.flags = LVFI_PARTIAL|LVFI_STRING;" to "tem.flags=LVFI_STRING;", it's a wrong case exactly. But now it isn't. :)

            1 Reply Last reply
            0
            • R rahuljin

              i have to list control in a mfc dialog application. first one is ipList. i want to search an item in the list.

              int i = 0;
              TCHAR ss[50] = {0};
              ipAdd.GetAddress(m_M1, m_M2, m_M3, m_M4);
              _stprintf_s(ss, _T("%d : %d : %d : %d"), m_M1, m_M2, m_M3, m_M4);

              for(int j=0; j < ipList.GetItemCount(); j++)
              {
              if(ipList.GetItem(j) != ss)
              i=0;
              else
              i = 1;
              }

              it gives the error ---

              error C2664: 'CListCtrl::GetItem' : cannot convert parameter 1 from 'int' to 'LVITEMW *'

              what i should do now ? btw thanks

              C Offline
              C Offline
              carter2000
              wrote on last edited by
              #36

              :)

              LVFINDINFO temp;
              CString ff;
              temp.flags = LVFI\_STRING | LVFI\_PARTIAL;    
              CStdioFile fileh;
              fileh.Open(L"C:\\\\srvc.txt", CFile::modeRead);	
              int i;
              do	
              {		
                  if(fileh.ReadString(ff)== NULL) 		
                  {			
                      break;		
                  }	
                  temp.psz = ff.GetBuffer();	
                  i = m\_objListCtrl.FindItem(&temp);
                  if(lstrcmp(m\_objListCtrl.GetItemText(i, 0), temp.psz) == 0)	
                  {		
                      m\_objListCtrl.SetCheck(i, TRUE);	
                  }		
              }
              while(ff.GetBuffer() != NULL);		
              fileh.Close();
              

              This can work in my computer, but I don't guarantee it could work in your computer. And by the way, I am in school now, but tomorrow I'll back home(There is no computer in my house :) ). It means I could not use computer for a long time. And I can't solve problem together with you, I'm sorry for that..

              1 Reply Last reply
              0
              • C carter2000

                You are right. :)

                R Offline
                R Offline
                rahuljin
                wrote on last edited by
                #37

                hello, is it possible to make edit control to take only numeric values and limited digits only ??? i have an edit control which is used for the port number, so i want that the user can enter only numeric value and 5 digits. any suggestion ??

                C 2 Replies Last reply
                0
                • R rahuljin

                  hello, is it possible to make edit control to take only numeric values and limited digits only ??? i have an edit control which is used for the port number, so i want that the user can enter only numeric value and 5 digits. any suggestion ??

                  C Offline
                  C Offline
                  carter2000
                  wrote on last edited by
                  #38

                  Yes, it can. you can set the property of the control to gain what you want. I forget the details, but I am sure it can. My computer do not have a compiler, so I can't take a test.

                  1 Reply Last reply
                  0
                  • R rahuljin

                    hello, is it possible to make edit control to take only numeric values and limited digits only ??? i have an edit control which is used for the port number, so i want that the user can enter only numeric value and 5 digits. any suggestion ??

                    C Offline
                    C Offline
                    carter2000
                    wrote on last edited by
                    #39

                    If your compiler is VS200X, you can right click the control, and click the "Add Variable" in the pop menus. Then it will pop out a window, and you can set the property in it. If your compiler is VC++6.0, select the control, and in the "View->Class Wizzard->Add Member", I hope I don't misremember.

                    R 1 Reply Last reply
                    0
                    • C carter2000

                      If your compiler is VS200X, you can right click the control, and click the "Add Variable" in the pop menus. Then it will pop out a window, and you can set the property in it. If your compiler is VC++6.0, select the control, and in the "View->Class Wizzard->Add Member", I hope I don't misremember.

                      R Offline
                      R Offline
                      rahuljin
                      wrote on last edited by
                      #40

                      i have vs2008. i set the limit by using this code ---

                      portID.SetLimitText(5);

                      only numeric problem is left.

                      modified on Wednesday, July 22, 2009 2:29 AM

                      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