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. Why I cannot have a ListControl in a CRecordView derived class?

Why I cannot have a ListControl in a CRecordView derived class?

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasehelpquestion
32 Posts 3 Posters 2 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.
  • L Offline
    L Offline
    Larry Mills Sr
    wrote on last edited by
    #1

    Here's some code: View declaration: class CCookItDBView : public CRecordView {      enum{ IDD = IDD_COOKITDB_FORM };      CMyDB* m_pSet; // Attributes public:      CCookItDBDoc* GetDocument() const;    void InsertItemsIngred();    void SetExtendedIngred();    void SetColumsIngred();// gives error at runtime NOT Compile time // Operations public:      // Ingredients LC      CListCtrl m_cIngred_LC;      CRecipeDataVec m_vRecipe;      CRecipeData m_cRecipeData; ..... }; void CCookItDBView::DoDataExchange(CDataExchange* pDX) {      CRecordView::DoDataExchange(pDX);      DDX_Control(pDX, IDC_INGRED_LC, m_cIngred_LC);IDC_INGRED_LC is the List Control and m_cIngred_LC is it's varable      // you can insert DDX_Field* functions here to 'connect' your controls to the database fields, ex.      // DDX_FieldText(pDX, IDC_MYEDITBOX, m_pSet->m_szColumn1, m_pSet);      // DDX_FieldCheck(pDX, IDC_MYCHECKBOX, m_pSet->m_bColumn2, m_pSet);      // See MSDN and ODBC samples for more information } void CCookItDBView::SetColumsIngred()      {      //CString csWorkDate = "";      CString csAmt = "Amount:";      CString csUnit = "Unit:";      CString csIngred = "Ingredients:";      // insert two columns (REPORT mode) and modify the new header items      CRect rect;      m_cIngred_LC.GetClientRect(&rect);// gives error at Runtime NOT compile Time      int nColInterval = rect.Width()/7;      m_cIngred_LC.InsertColumn(0, csAmt, LVCFMT_LEFT, nColInterval*2);      m_cIngred_LC.InsertColumn(1, csUnit, LVCFMT_LEFT, nColInterval*2);      m_cIngred_LC.InsertColumn(2, csIngred, LVCFMT_LEFT, nColInterval*2);      }

    A C++ programming language novice, but striving to learn

    _ 1 Reply Last reply
    0
    • L Larry Mills Sr

      Here's some code: View declaration: class CCookItDBView : public CRecordView {      enum{ IDD = IDD_COOKITDB_FORM };      CMyDB* m_pSet; // Attributes public:      CCookItDBDoc* GetDocument() const;    void InsertItemsIngred();    void SetExtendedIngred();    void SetColumsIngred();// gives error at runtime NOT Compile time // Operations public:      // Ingredients LC      CListCtrl m_cIngred_LC;      CRecipeDataVec m_vRecipe;      CRecipeData m_cRecipeData; ..... }; void CCookItDBView::DoDataExchange(CDataExchange* pDX) {      CRecordView::DoDataExchange(pDX);      DDX_Control(pDX, IDC_INGRED_LC, m_cIngred_LC);IDC_INGRED_LC is the List Control and m_cIngred_LC is it's varable      // you can insert DDX_Field* functions here to 'connect' your controls to the database fields, ex.      // DDX_FieldText(pDX, IDC_MYEDITBOX, m_pSet->m_szColumn1, m_pSet);      // DDX_FieldCheck(pDX, IDC_MYCHECKBOX, m_pSet->m_bColumn2, m_pSet);      // See MSDN and ODBC samples for more information } void CCookItDBView::SetColumsIngred()      {      //CString csWorkDate = "";      CString csAmt = "Amount:";      CString csUnit = "Unit:";      CString csIngred = "Ingredients:";      // insert two columns (REPORT mode) and modify the new header items      CRect rect;      m_cIngred_LC.GetClientRect(&rect);// gives error at Runtime NOT compile Time      int nColInterval = rect.Width()/7;      m_cIngred_LC.InsertColumn(0, csAmt, LVCFMT_LEFT, nColInterval*2);      m_cIngred_LC.InsertColumn(1, csUnit, LVCFMT_LEFT, nColInterval*2);      m_cIngred_LC.InsertColumn(2, csIngred, LVCFMT_LEFT, nColInterval*2);      }

      A C++ programming language novice, but striving to learn

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

      Where are you calling SetColumsIngred from. You cannot call it from the dialog constructor. It has to be called From the OnInitDialog function.

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

      L 1 Reply Last reply
      0
      • _ _Superman_

        Where are you calling SetColumsIngred from. You cannot call it from the dialog constructor. It has to be called From the OnInitDialog function.

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

        L Offline
        L Offline
        Larry Mills Sr
        wrote on last edited by
        #3

        void CCookItDBView::OnInitialUpdate() {      SetColumsIngred();      m_pSet = &GetDocument()->m_CookItDBSet; } ass you can see, I am calling it from the CRecordView class (see previous header code)

        A C++ programming language novice, but striving to learn

        _ D 2 Replies Last reply
        0
        • L Larry Mills Sr

          void CCookItDBView::OnInitialUpdate() {      SetColumsIngred();      m_pSet = &GetDocument()->m_CookItDBSet; } ass you can see, I am calling it from the CRecordView class (see previous header code)

          A C++ programming language novice, but striving to learn

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

          Set a breakpoint in OnInitialUpdate and single step into SetColumsIngred.

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

          L 1 Reply Last reply
          0
          • _ _Superman_

            Set a breakpoint in OnInitialUpdate and single step into SetColumsIngred.

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

            L Offline
            L Offline
            Larry Mills Sr
            wrote on last edited by
            #5

            I did that already. That's how I know where if crashes. I crashes on the three lines I indicated above.

            A C++ programming language novice, but striving to learn

            1 Reply Last reply
            0
            • L Larry Mills Sr

              void CCookItDBView::OnInitialUpdate() {      SetColumsIngred();      m_pSet = &GetDocument()->m_CookItDBSet; } ass you can see, I am calling it from the CRecordView class (see previous header code)

              A C++ programming language novice, but striving to learn

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

              Does the list control window exist at this point?

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              L 1 Reply Last reply
              0
              • D David Crow

                Does the list control window exist at this point?

                "One man's wage rise is another man's price increase." - Harold Wilson

                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                L Offline
                L Offline
                Larry Mills Sr
                wrote on last edited by
                #7

                Yes!

                A C++ programming language novice, but striving to learn

                D 1 Reply Last reply
                0
                • L Larry Mills Sr

                  Yes!

                  A C++ programming language novice, but striving to learn

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

                  So then what's the error?

                  "One man's wage rise is another man's price increase." - Harold Wilson

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  L 1 Reply Last reply
                  0
                  • D David Crow

                    So then what's the error?

                    "One man's wage rise is another man's price increase." - Harold Wilson

                    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                    L Offline
                    L Offline
                    Larry Mills Sr
                    wrote on last edited by
                    #9

                    David it doesn't give an error, it just crashes.

                    A C++ programming language novice, but striving to learn

                    D 1 Reply Last reply
                    0
                    • L Larry Mills Sr

                      David it doesn't give an error, it just crashes.

                      A C++ programming language novice, but striving to learn

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

                      Larry Mills Sr wrote:

                      ...it just crashes.

                      Assertion, exception, what?

                      "One man's wage rise is another man's price increase." - Harold Wilson

                      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                      L 1 Reply Last reply
                      0
                      • D David Crow

                        Larry Mills Sr wrote:

                        ...it just crashes.

                        Assertion, exception, what?

                        "One man's wage rise is another man's price increase." - Harold Wilson

                        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                        L Offline
                        L Offline
                        Larry Mills Sr
                        wrote on last edited by
                        #11

                        //This crashes because as you indicated the window has not been created yet: void CCookItDBView::OnInitialUpdate() {      m_pSet = &GetDocument()->m_CookItDBSet;      SetColumsIngred();      CRecordView::OnInitialUpdate(); } // THIS IS CORRECT   IT WORKS NOW void CCookItDBView::OnInitialUpdate() {      m_pSet = &GetDocument()->m_CookItDBSet;      CRecordView::OnInitialUpdate();      SetColumsIngred(); } I didn't understand you previous comment until in debug I caught it. Thanks David. Question: I have several "Tables" in the database that hopefully will point me to data contained in other tables that are not presently linked in the RecordSet. For example: Table "RecipeData" is not linked in the RecordSet (I didn't select it when I selected the Tables) can I still do this:   CString str = m_pSet->[RecordDate].Recipe;

                        A C++ programming language novice, but striving to learn

                        D 1 Reply Last reply
                        0
                        • L Larry Mills Sr

                          //This crashes because as you indicated the window has not been created yet: void CCookItDBView::OnInitialUpdate() {      m_pSet = &GetDocument()->m_CookItDBSet;      SetColumsIngred();      CRecordView::OnInitialUpdate(); } // THIS IS CORRECT   IT WORKS NOW void CCookItDBView::OnInitialUpdate() {      m_pSet = &GetDocument()->m_CookItDBSet;      CRecordView::OnInitialUpdate();      SetColumsIngred(); } I didn't understand you previous comment until in debug I caught it. Thanks David. Question: I have several "Tables" in the database that hopefully will point me to data contained in other tables that are not presently linked in the RecordSet. For example: Table "RecipeData" is not linked in the RecordSet (I didn't select it when I selected the Tables) can I still do this:   CString str = m_pSet->[RecordDate].Recipe;

                          A C++ programming language novice, but striving to learn

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

                          Yes, you can reference whatever tables you want in the GetDefaultSQL() method. Make sure that the fields in the query match the order of the associated variables in the DoFieldExchange() method.

                          "One man's wage rise is another man's price increase." - Harold Wilson

                          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                          L 1 Reply Last reply
                          0
                          • D David Crow

                            Yes, you can reference whatever tables you want in the GetDefaultSQL() method. Make sure that the fields in the query match the order of the associated variables in the DoFieldExchange() method.

                            "One man's wage rise is another man's price increase." - Harold Wilson

                            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                            L Offline
                            L Offline
                            Larry Mills Sr
                            wrote on last edited by
                            #13

                            David, I tried to write to the DB and I get an error "The RecordSet is read only."   How do I change that?

                            A C++ programming language novice, but striving to learn

                            D 1 Reply Last reply
                            0
                            • L Larry Mills Sr

                              David, I tried to write to the DB and I get an error "The RecordSet is read only."   How do I change that?

                              A C++ programming language novice, but striving to learn

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

                              If your query is joining multiple tables, it cannot be updated (i.e., read-only).

                              "One man's wage rise is another man's price increase." - Harold Wilson

                              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                              L 2 Replies Last reply
                              0
                              • D David Crow

                                If your query is joining multiple tables, it cannot be updated (i.e., read-only).

                                "One man's wage rise is another man's price increase." - Harold Wilson

                                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                                L Offline
                                L Offline
                                Larry Mills Sr
                                wrote on last edited by
                                #15

                                So how do I update, ie Read, Write or delete an individual table's record. Do I have to create a DSN for each table or what?

                                A C++ programming language novice, but striving to learn

                                D 1 Reply Last reply
                                0
                                • L Larry Mills Sr

                                  So how do I update, ie Read, Write or delete an individual table's record. Do I have to create a DSN for each table or what?

                                  A C++ programming language novice, but striving to learn

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

                                  Larry Mills Sr wrote:

                                  So how do I update, ie Read, Write or delete an individual table's record.

                                  Yes. Those tables should all be linked together via a primary/foreign key.

                                  Larry Mills Sr wrote:

                                  Do I have to create a DSN for each table or what?

                                  No, but you may end up with several recordset classes.

                                  "One man's wage rise is another man's price increase." - Harold Wilson

                                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                                  L 1 Reply Last reply
                                  0
                                  • D David Crow

                                    Larry Mills Sr wrote:

                                    So how do I update, ie Read, Write or delete an individual table's record.

                                    Yes. Those tables should all be linked together via a primary/foreign key.

                                    Larry Mills Sr wrote:

                                    Do I have to create a DSN for each table or what?

                                    No, but you may end up with several recordset classes.

                                    "One man's wage rise is another man's price increase." - Harold Wilson

                                    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                                    L Offline
                                    L Offline
                                    Larry Mills Sr
                                    wrote on last edited by
                                    #17

                                    David, I don't understand your response. The tables are all loaded, but I cannot write or delete any records in them. How exactly do I write to one of the tables to add a new record? How dom I set CanUpdate() and CanAppend() to TRUE. Nowhere in the Wizzard supplied Recordset class is there an "Open(....)" statement so I can change anything, so just how do I get to write tothe database?

                                    A C++ programming language novice, but striving to learn

                                    D 1 Reply Last reply
                                    0
                                    • L Larry Mills Sr

                                      David, I don't understand your response. The tables are all loaded, but I cannot write or delete any records in them. How exactly do I write to one of the tables to add a new record? How dom I set CanUpdate() and CanAppend() to TRUE. Nowhere in the Wizzard supplied Recordset class is there an "Open(....)" statement so I can change anything, so just how do I get to write tothe database?

                                      A C++ programming language novice, but striving to learn

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

                                      Larry Mills Sr wrote:

                                      ...but I cannot write or delete any records in them

                                      Make sure the DSN, the CDatabase object, and the CRecordset object are all opened correctly (i.e., non read-only).

                                      Larry Mills Sr wrote:

                                      How exactly do I write to one of the tables to add a new record?

                                      Use the CRecordset::AddNew() followed by CRecordset::Update().

                                      Larry Mills Sr wrote:

                                      Nowhere in the Wizzard supplied Recordset class is there an "Open(....)" statement...

                                      See here. While it does not do any updating, you might check out this[^] article.

                                      "One man's wage rise is another man's price increase." - Harold Wilson

                                      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                                      L 1 Reply Last reply
                                      0
                                      • D David Crow

                                        Larry Mills Sr wrote:

                                        ...but I cannot write or delete any records in them

                                        Make sure the DSN, the CDatabase object, and the CRecordset object are all opened correctly (i.e., non read-only).

                                        Larry Mills Sr wrote:

                                        How exactly do I write to one of the tables to add a new record?

                                        Use the CRecordset::AddNew() followed by CRecordset::Update().

                                        Larry Mills Sr wrote:

                                        Nowhere in the Wizzard supplied Recordset class is there an "Open(....)" statement...

                                        See here. While it does not do any updating, you might check out this[^] article.

                                        "One man's wage rise is another man's price increase." - Harold Wilson

                                        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                                        L Offline
                                        L Offline
                                        Larry Mills Sr
                                        wrote on last edited by
                                        #19

                                        David Crow wrote: Make sure the DSN, the CDatabase object, and the CRecordset object are all opened correctly (i.e., non read-only). David, that's what I'm trying to found out how to do! All I've done since the the Wizard create the Recordset class is compile the program, which did so correctly. Am I supposed to do a database "Open(....) statement somewhere. I didn't see that in your I "Invoice" program anywhere. I simply don't know what to do at this point. Help please!

                                        A C++ programming language novice, but striving to learn

                                        D 1 Reply Last reply
                                        0
                                        • L Larry Mills Sr

                                          David Crow wrote: Make sure the DSN, the CDatabase object, and the CRecordset object are all opened correctly (i.e., non read-only). David, that's what I'm trying to found out how to do! All I've done since the the Wizard create the Recordset class is compile the program, which did so correctly. Am I supposed to do a database "Open(....) statement somewhere. I didn't see that in your I "Invoice" program anywhere. I simply don't know what to do at this point. Help please!

                                          A C++ programming language novice, but striving to learn

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

                                          Larry Mills Sr wrote:

                                          David, that's what I'm trying to found out how to do!

                                          Does the query contain any JOINs?

                                          Larry Mills Sr wrote:

                                          Am I supposed to do a database "Open(....) statement somewhere.

                                          It's not necessary since CRecordset also has an Open() method.

                                          "One man's wage rise is another man's price increase." - Harold Wilson

                                          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                                          L 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