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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Deleting a item from ComboBox..

Deleting a item from ComboBox..

Scheduled Pinned Locked Moved C / C++ / MFC
questiondatabase
16 Posts 5 Posters 1 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 mpallavi

    Thank you all.. Can anyone tell me how do i get the data associated with the current selection .. i mean the value of the current selection. thanx pallavi

    T Offline
    T Offline
    ThatsAlok
    wrote on last edited by
    #6

    mpallavi wrote: Can anyone tell me how do i get the data associated with the current selection .. See it this Help CComboBox::GetLBText Here is small code to help :-

    int nIndex=m_combo.GetCurSel();
    if(nIndex==LB_ERR)
    {
    CString str;
    m_combo.GetLBText(nIndex,str);
    }

    "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

    cheers, Alok Gupta

    J M 2 Replies Last reply
    0
    • T ThatsAlok

      mpallavi wrote: Can anyone tell me how do i get the data associated with the current selection .. See it this Help CComboBox::GetLBText Here is small code to help :-

      int nIndex=m_combo.GetCurSel();
      if(nIndex==LB_ERR)
      {
      CString str;
      m_combo.GetLBText(nIndex,str);
      }

      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

      cheers, Alok Gupta

      J Offline
      J Offline
      Jose Lamas Rios
      wrote on last edited by
      #7

      ThatsAlok wrote: if(nIndex==LB_ERR) I think you mean if(nIndex!=LB_ERR) Technically, in this case CB_ERR should be used instead of LB_ERR, but in practice both are defined as -1 :) Hey, this peer programming thing does work! :-) -- jlr http://jlamas.blogspot.com/[^]

      T 1 Reply Last reply
      0
      • J Jose Lamas Rios

        ThatsAlok wrote: if(nIndex==LB_ERR) I think you mean if(nIndex!=LB_ERR) Technically, in this case CB_ERR should be used instead of LB_ERR, but in practice both are defined as -1 :) Hey, this peer programming thing does work! :-) -- jlr http://jlamas.blogspot.com/[^]

        T Offline
        T Offline
        ThatsAlok
        wrote on last edited by
        #8

        Jose Lamas Rios wrote: I think you mean if(nIndex!=LB_ERR) Yeap, Sorry for Silly Mistake :) Jose Lamas Rios wrote: Hey, this peer programming thing does work! Yeap, thats why we are here :)

        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

        cheers, Alok Gupta

        1 Reply Last reply
        0
        • T ThatsAlok

          mpallavi wrote: Can anyone tell me how do i get the data associated with the current selection .. See it this Help CComboBox::GetLBText Here is small code to help :-

          int nIndex=m_combo.GetCurSel();
          if(nIndex==LB_ERR)
          {
          CString str;
          m_combo.GetLBText(nIndex,str);
          }

          "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

          cheers, Alok Gupta

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

          Thanx.. its working. I have still more problems with ComboBox.. I am saving all these telephone numbers in a text file.. If you remember, few days back i was coding for persistent combo box. Its working perfactly fine but the problem is when i delete a number. I am creating a temp file .. i want to write all the values in this file except for the current selection.. how do i go about this? pallavi

          T 1 Reply Last reply
          0
          • M mpallavi

            Thanx.. its working. I have still more problems with ComboBox.. I am saving all these telephone numbers in a text file.. If you remember, few days back i was coding for persistent combo box. Its working perfactly fine but the problem is when i delete a number. I am creating a temp file .. i want to write all the values in this file except for the current selection.. how do i go about this? pallavi

            T Offline
            T Offline
            ThatsAlok
            wrote on last edited by
            #10

            mpallavi wrote: I am creating a temp file .. i want to write all the values in this file except for the current selection.. how do i go about this? Let this variable m_arr of type CStringArray contain all the phone number present in combo box.

            // first get Phone Number to delete
            CString szPhoneNo;

            int nIndex=m_combo.GetCurSel();
            if(nIndex!=CB_ERR) //thanks to Mr. Rios :)
            {
            m_combo.GetLBText(nIndex,szPhoneNo);
            }
            else
            // no string to delete from file
            return;

            // Open Temporary File
            CString szTempPath;
            GetTempPath(szTempPath.GetBuffer(MAX_PATH),MAX_PATH);

            // release buffer get control of Path
            szTempPath.ReleaseBuffer();

            //Include our File Name in path
            szTempPath+=CString("temp.txt");

            // Now Open Text File
            CStdioFile m_File;

            if(m_File.Open(szTempPath,CFile::modeCreate|CFile:modeWrite))
            {

            for(int i=0;i<m_arr.GetUpperBound();i++)
            {
            //copy data
            if(m_arr.GetAt(i)!=szPhoneNo)
            m_File.WriteString(m_arr.GetAt(i));

            }

            m_File.Close();
            }

            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

            cheers, Alok Gupta

            M 1 Reply Last reply
            0
            • T ThatsAlok

              mpallavi wrote: I am creating a temp file .. i want to write all the values in this file except for the current selection.. how do i go about this? Let this variable m_arr of type CStringArray contain all the phone number present in combo box.

              // first get Phone Number to delete
              CString szPhoneNo;

              int nIndex=m_combo.GetCurSel();
              if(nIndex!=CB_ERR) //thanks to Mr. Rios :)
              {
              m_combo.GetLBText(nIndex,szPhoneNo);
              }
              else
              // no string to delete from file
              return;

              // Open Temporary File
              CString szTempPath;
              GetTempPath(szTempPath.GetBuffer(MAX_PATH),MAX_PATH);

              // release buffer get control of Path
              szTempPath.ReleaseBuffer();

              //Include our File Name in path
              szTempPath+=CString("temp.txt");

              // Now Open Text File
              CStdioFile m_File;

              if(m_File.Open(szTempPath,CFile::modeCreate|CFile:modeWrite))
              {

              for(int i=0;i<m_arr.GetUpperBound();i++)
              {
              //copy data
              if(m_arr.GetAt(i)!=szPhoneNo)
              m_File.WriteString(m_arr.GetAt(i));

              }

              m_File.Close();
              }

              "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

              cheers, Alok Gupta

              M Offline
              M Offline
              mpallavi
              wrote on last edited by
              #11

              ThatsAlok wrote: GetTempPath(szTempPath.GetBuffer(MAX_PATH),MAX_PATH); I am getting the following error at above line: 'GetTempPathA' : cannot convert parameter 1 from 'char *' to 'unsigned long' Please help.

              T 1 Reply Last reply
              0
              • M mpallavi

                ThatsAlok wrote: GetTempPath(szTempPath.GetBuffer(MAX_PATH),MAX_PATH); I am getting the following error at above line: 'GetTempPathA' : cannot convert parameter 1 from 'char *' to 'unsigned long' Please help.

                T Offline
                T Offline
                ThatsAlok
                wrote on last edited by
                #12

                mpallavi wrote: GetTempPath(szTempPath.GetBuffer(MAX_PATH),MAX_PATH); Sorry, Just Exchange Argument :) i.e.

                GetTempPath(MAX_PATH,szTempPath.GetBuffer(MAX_PATH));

                "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                cheers, Alok Gupta

                M 2 Replies Last reply
                0
                • T ThatsAlok

                  mpallavi wrote: GetTempPath(szTempPath.GetBuffer(MAX_PATH),MAX_PATH); Sorry, Just Exchange Argument :) i.e.

                  GetTempPath(MAX_PATH,szTempPath.GetBuffer(MAX_PATH));

                  "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                  cheers, Alok Gupta

                  M Offline
                  M Offline
                  mpallavi
                  wrote on last edited by
                  #13

                  Hi Alok.. temp file is getting created but its empty.. i am trying to find what went wrong.. :( regards pallavi

                  1 Reply Last reply
                  0
                  • T ThatsAlok

                    mpallavi wrote: GetTempPath(szTempPath.GetBuffer(MAX_PATH),MAX_PATH); Sorry, Just Exchange Argument :) i.e.

                    GetTempPath(MAX_PATH,szTempPath.GetBuffer(MAX_PATH));

                    "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                    cheers, Alok Gupta

                    M Offline
                    M Offline
                    mpallavi
                    wrote on last edited by
                    #14

                    oops.. My array of strings is empty.. I used m_arr.Add(m_strPhoneNum); to add phone numbers in the array. I think the syntax is wrong.. pallavi.

                    D T 2 Replies Last reply
                    0
                    • M mpallavi

                      oops.. My array of strings is empty.. I used m_arr.Add(m_strPhoneNum); to add phone numbers in the array. I think the syntax is wrong.. pallavi.

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #15

                      mpallavi wrote: m_arr.Add(m_strPhoneNum); what is m_arr, and how are you iterating throught it when writing to the file?


                      "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

                      1 Reply Last reply
                      0
                      • M mpallavi

                        oops.. My array of strings is empty.. I used m_arr.Add(m_strPhoneNum); to add phone numbers in the array. I think the syntax is wrong.. pallavi.

                        T Offline
                        T Offline
                        ThatsAlok
                        wrote on last edited by
                        #16

                        mpallavi wrote: to add phone numbers in the array. I think the syntax is wrong.. Hi Pal, First Add all the member of ComboBox to CStringArray or directly Enumerate them, When you are entering data in temporary File.

                        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                        cheers, Alok Gupta

                        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