Click here to Skip to main content
14,825,860 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

i have created gridcontrol from list control. now i want to save the object of the list control and when i open the application i want to load it again.

So, please help me...



Thanks.
Posted

Good background info on MFC serialization: Microsoft Visual C++/MFC File Processing: Serialization[^].
   
Comments
Member 10474623 28-Jan-14 23:54pm
   
Thanks...

But my problem is that "When i save the object,i have to send each item to the class that is derived from the CObject. but i don't want to send each item but i want to send the object at a time. "

for Ex...
i have created a class CSave from CObject. and i have one list control object m_lstDemo.
now when we want to serialize we have to do like this

CSave *itm=new CSave(m_lstDemo.GetItemText(0,0),m_lstDemo.GetItemText(0,1),m_lstDemo.GetItemText(0,2));
CSave *itm1 = new CSave(&m_lstDemo);

but i want to save m_latDemo object at a time because i have so many data to save. so this is not possible.

so, please let me know how to do this ?
CPallini 29-Jan-14 3:14am
   
You have to save all the items, of course. However you might create a new class, inheriting from the list control and implement the serialization just once there.
Member 10474623 30-Jan-14 0:09am
   
Thank a lot...

Can you please let me know how to take array of strings so that i take array of m_lstDemo.GetItemtext(i,j). how to pass the array and how to retrieve it.
After Searching a lot i got my solution and it is like this.

1) Take CArray.
i have created a CSave class from CObject.
In the header file i have to declare like this.
class CSave : public CObject
{
public:
CSave();
CSave(CSave &item);
CSave &operator =(CSave &item);
virtual ~CSave();
public:
CString str[120];
}

2) In the source file(.cpp) declare like this

C#
CSave::CSave(CSave &item)
{
    int j=0;
    for(int Row=0;Row<20;Row++)
    {
        for(int Col=0;Col<6;Col++,j++)
        {
            str[j]=item.str[j];
        }
    }
}


3) For Serialization do like this

C#
void CSave::Serialize(CArchive& ar)
{
    CObject::Serialize(ar);

    if( ar.IsStoring() )
    {
        int j=0;
        for(int Row=0;Row<20;Row++)
        {
            for(int Col=0;Col<6;Col++,j++)
            {
                ar<<str[j];
            }
        }
    }

     else
    {
        int j=0;
        for(int Row=0;Row<20;Row++)
        {
            for(int Col=0;Col<6;Col++,j++)
            {
                ar>>str[j];
            }
        }
    }
   
}



4)In the dialog source file (.cpp) add this for adding data to serialization....

C#
CSave itm;
    int j=0;
    for(int Row=0;Row<20;Row++)
    {
        for(int Col=0;Col<6;Col++,j++)
        {
            itm.str[j]=m_lstDemo.GetItemText(Row,Col);
        }
    }
    CSave *item = new CSave(itm);
    ListOfData.Add(item);



5) For Reading data back ..
XML
CSave *itm=reinterpret_cast<CSave *>(ListOfData[0]);

    int j=0;
    for(int Row=0;Row<20;Row++)
    {
        for(int Col=0;Col<6;Col++,j++)

        {
            m_lstDemo.SetItemText(Row,Col,itm->str[j]);
        }
    }


That's it...
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900