????? ??? ???? ???? DataGrid ArrayList ?? ???????? ?? ????? ???????? .NET Visual C++ ?? Visual C++ 2005

?????? ????????? ?????? ?????????
???? ???????: 816164 - ??? ???????? ???? ????? ????? ??? ???????.
????? ???? | ?? ????

?? ??? ??????

??????

???? ??? ??????? ???? ????? ??? ????? ??? ????? ArrayList ???????? ??? ???? ???? DataGrid. ?????? ????? ????? Windows ?? ???? ???? DataGrid ???? ??? ??????? ?????? ?????? ????? ????? ??????? ??????? ?????? ?????? DataGrid.

???????

????? ??? ??????? ??? ??????? ??? ???????? ???????:
  • ???? .NET C++ ?? Visual C++ 2005 ????? ????????
???? ??????? ??????? ??????? ?????? ??? ????? ?????? ???????? ?????? ? ??? ??????? ???? ???????:
  • 2005 C++ .NET Microsoft Visual C++ ?? Visual Microsoft

????? ???

???? ??? ??? ???? ???? ??? ?? ???? ????? accessors ???????. ??? ?? ????? ?? ????? ??? ???? getter ???? setter. ????? ??????? ???????? ?????? getter ??????? setter ??? ?????? ?????? ??????? ?? ??? ?? ??????? ??????? ???? ?????? ?????? ???????? __property. ????? ??? ????? ????????? ?? ??? ??????? ????? ?????:
__gc class Guitar
{
private:
        String *make;
        String *model;
        short year;
public:
    Guitar(void);
    ~Guitar(void);
        
        Guitar(String *strMake, String *strModel, short shYear)
        {
            make = strMake;
            model = strModel;
            year = shYear;
        }

        __property String* get_Make() 
        {
            return make; 
        }
        __property void set_Make(String* val)
        {
            make = (val); 
        }
        __property String* get_Model()
        { 
            return model; 
        }
        __property void set_Model(String* val)
        {
            model = (val); 
        }

        __property short get_Year()
        { 
            return year; 
        }
        __property void set_Year(short shValue)
        {
            year = shValue; 
        }
};

????? ?????? ??? ??? ArrayList

????? ?????? ???????? ??? ??? ArrayList ???? ??????? ???????:
  1. ???? ?????? ????? ArrayList ??? ???:
    private: ArrayList *arrayList;
  2. ?? ????? ??????? FormLoad ????? ?????? ????? ?? ?? ?????? ???????? ??? ??? ArrayList ??? ???: //Create
    //Create an ArrayList.
    arrayList = new ArrayList();
    
    //Populate the array list.
    arrayList->Add(new guitar(S"GibSon",S"Les Paul",1958));
    arrayList->Add(new guitar(S"Fender",S"Jazz Bass",1958));
    arrayList->Add(new guitar(S"Guild",S"Bluesbird",1958));
    

??? ?? ArrayList DataGrid

??? ?? ??? ????? ??? ArrayList ????? ??????? DataSource ????? ?????? DataGrid ??? ??? ArrayList. ??? ????? ??????? ???????? ?? ???? ?????? DataGrid ????? ??? ????? ?????? ???? accessors ??????? ?? ??????.
// Bind the Array List to DataGrid.
      dataGrid1->DataSource = arrayList;

??? ??? ArrayList

????? ??????? ??? CurrencyManager ?????? ???? ??? ArrayList. ?????? ????? ????? ????? ???? CurrencyManager ??? ???:
private: CurrencyManager *currencyManager;
?????? ??? CurrencyManager ?? ?????? BindingContext ???? ?????? (?? ??? ??????? ArrayList). currencyManager
currencyManager = (CurrencyManager*)dataGrid1->BindingContext
->Item[arrayList];
????? ??? CurrencyManager ????? ???? ????? ?????? ????? ??? ????? ????? ArrayList. ?? ???? ????? ??? ?? ??? ?? ?????? ??????? ?????? ??????, ????? ?????? ??? ?????? ?????? DataGrid. ?????? //Move
//Move forward one element.
currencyManager.Position++;
//Move back one element.
currencyManager.Position--;
//Move to the beginning.
currencyManager.Position = 0;
//Move to the end.
currencyManager.Position = arrayList.Count - 1;
				

???? ???? ?????

  1. ??? ????? Microsoft Visual Studio .NET 2003 ?? Microsoft Visual Studio 2005.
  2. ?? ??????? ???? ??? ??? ???? ?? ???? ??? ???????.
  3. ???? ??? ?????? Visual C++ ??? ????? Project ?? ???? ??? ????? ????? Windows (.NET) ??? ?????.

    ?????? ?? Visual Studio 2005 ? ???? ??? Visual C++ ??? ????? Project ?? ???? ??? ????? ????? Windows ??? ?????.
  4. ?? ???? ???? ??? ???? Q816164 ??? ?? ???? ??? ?????.
  5. ?? "?????? ??????" ???????? ??? "????? ??? ?????". ?????? ????? ???? ??? ??? ??? ?? ??????? ???.
  6. ???? ??? ?????? ?????? ??? Q816164 ? ??? ??? ????? ?? ???? ??? ????? ???.
  7. ?? ???? ?????? ????? ??? ? ???? ??? ??? C++ ??? ??? ????? ?? ???? ??? ???.

    ?????? ?? Visual Studio 2005 ? ???? ??? Cass C++ ??? ????? ?? ???? ??? ?????.
  8. ?? "????? ??? C++ ???" ???? Guitar ?? ???? ???? ??? ??? ?? ???? ??? ?????. ???? ??? Guitar ??? ???:
    #pragma once
    
    class Guitar
    {
    public:
    	Guitar(void);
    	~Guitar(void);
    };
    
    ?????? ?? Visual Studio 2005 ???????? ???????? ??? ???.
    #pragma once
    
    ref class Guitar
    {
    public:
    	Guitar(void);
    };
    
    ???? Guitar ????? ??? "?????? ?????" ???? ?? C++ ????? ?????? ???????? __gc ??? ??? Guitar ??? ???:
    __gc class Guitar
    {
    public:
    	Guitar(void);
    	~Guitar(void);
    };
    
  9. Replace the existing code in the Guitar.h file with the following code:
    #pragma once
    
    using namespace System;
    __gc class Guitar
    {
    private:
            String *make;
            String *model;
            short year;
    public:
        Guitar(void);
        ~Guitar(void);
            
            Guitar(String *strMake, String *strModel, short shYear)
            {
                make = strMake;
                model = strModel;
                year = shYear;
            }
    
            __property String* get_Make() 
            {
                return make; 
            }
            __property void set_Make(String* val)
            {
                make = (val); 
            }
            __property String* get_Model()
            { 
                return model; 
            }
            __property void set_Model(String* val)
            {
                model = (val); 
            }
    
            __property short get_Year()
            { 
                return year; 
            }
            __property void set_Year(short shValue)
            {
                year = shValue; 
            }
    };
    
    
    Note You must add the common language runtime support compiler option (/clr:oldSyntax) in Visual C++ 2005 to successfully compile the previous code sample. ?????? ??????? ??? ??? ??????? ??? ?????? ??????? ??????? ?????? ?? Visual C++ 2005 ???? ??????? ???????:
    1. ???? ??? Project ?? ???? ??? <ProjectName> ?????.

      ??????<ProjectName> ?????? ?????? ??? ???????.
    2. ?? ?????? ????? ????? ?? ???? ??? ???.
    3. ???? ?????? ??? ????? ????? ?????? ??? ? ?????? ??????? (/ clr:oldSyntax) ?? ??????? ??????? ????? "??? ????? ????? ??????" ?? ????? ?????? ???? ??? ????? ?? ???? ??? ?????.
    ?????? ??? ???? ?? ????????? ??? ??? ????? ????? ?????? ????? ?????? ?????? ??????? ??????? ?? ?????? ???? Microsoft ?????? ??? ?????:
    / ??? (??????? ??? ????? ????? ??????)
    http://msdn2.microsoft.com/en-us/library/k8d11d4s.aspx
  10. ????? ???? ????????? ???????? Guitar.h ??? ?? ??????? ??? "???? ???????".
  11. ????? ???? ???? DataGrid ??? Form1. ??? ???? ?????? DataGrid ??????? ????? ????? ????? ???????.
  12. ????? ????? ????? ???? ?? ??? Form1 ??? ?? ????? ??????? ??????.
  13. ????? ??????? TextButton1 ??? ??????.
  14. ????? ??????? TextButton2 ??? ??????.
  15. ????? ??????? TextButton3 ??? ?????.
  16. ????? ??????? TextButton4 ??? ???.
  17. ???? ????? Form1.h ??? ?????? ???????? ???????? ??????? ?? ???????:
    #include "Guitar.h"
  18. ?? ?????? ????????? ???????? ??????? ??? ??? Form1:
    private: System::Collections::ArrayList *arrayList;	
    private: System::Windows::Forms::CurrencyManager *currencyManager;	
    
  19. ??????? ??? "???? ?????" ???? ??? ?????? ?????? ??? form1 ?? ???? ??? ?????.
  20. ???? ??? ??? ????? ??? ?? ???? ????? ??????? ??? ????? Load ?????? ??? Form1_Load ??? ????????? ???????? ?????? ??.
  21. ?? ???? ???????? ???????? ??????? ?? ????? Form1_Load: //Create
    //Create an arraylist.
    arrayList = new ArrayList();
    
    arrayList->Add(new Guitar(S"GibSon",S"Les Paul",1958));
    arrayList->Add(new Guitar(S"Fender",S"Jazz Bass",1958));
    arrayList->Add(new Guitar(S"Guild",S"Bluesbird",1958));
    
                
     currencyManager = dynamic_cast <CurrencyManager*>
                     (dataGrid1->BindingContext->Item[arrayList]);
    // Bind the Array List to DataGrid.
    dataGrid1->DataSource = arrayList;
    
  22. ??????? ??? ???? ???????.
  23. ???? ????? ??????? ??? ?????? ?? ?? ?????? ???????? ???????? ??????? ??? ????? button1_Click: //Move
    //Move to the next position.
    currencyManager->Position++;
    
  24. ???? ????? ??????? ??? ?????? ? ?? ?? ?????? ???????? ???????? ??????? ??? ????? button2_Click: //Move
    //Move to the previous position.
    currencyManager->Position--;
    
  25. ???? ????? ??????? ??? ????? ?? ?? ?????? ???????? ???????? ??????? ??? ????? button3_Click: //Move
    //Move to the first position.
    currencyManager->Position =0;
    
  26. ???? ????? ??????? ??? ??? ?? ?? ?????? ???????? ???????? ??????? ??? ????? button4_Click: //Move
    //Move to the last position.
    currencyManager->Position = currencyManager->Count -1;
    
  27. ????? ?? ?? ?????? ???????.
  28. ???? ??? ????? ??????? ?????? ???? ???? ?????? DataGrid. ???? ??? ????? ????? ??? ???????? ? ??? ??? ????? ???.

?????

????? ?? ????????? ??? ??????? ?? ???????? ?? ??????? Windows ? ?? ?????? ???? Microsoft ??? ??? ?????? ???????:
http://msdn2.microsoft.com/en-us/library/aa983578(VS.71).aspx

???????

???? ???????: 816164 - ????? ??? ??????: 26/???? ??????/1428 - ??????: 2.2
????? ???
  • Microsoft Visual C++ 2005 Express Edition
  • Microsoft Visual C++ .NET 2003 Standard Edition
????? ??????: 
kbmt kbdatabinding kbcollections kbhowtomaster kbhowto KB816164 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????816164

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com