???????? ?? ???????? ???? ArrayList ???? ?? ??? Visual Basic 2005 ?? Visual Basic .NET ?? ????? ?? ???? DataGrid ???????? ????? ???? ?? ??? ???? ????

???? ?????? ???? ??????
???? ID: 316302 - ?? ???????? ?? ?????? ??? ?? ?? ???? ???? ???? ??.
?? Microsoft Visual C# .NET ??????? ?? ??? ?? ???? ??, ?????316303.
??? ?? ??????? ???? | ??? ?? ??????? ????

?? ????? ??

??????

?? ??? ?? ??? ???? ????? ?? ?? ???? ????? ???? ?? ??? ???ArrayList???? ?? ??? ???????? ?? ???DataGrid???????? ??? ?????? ?? ??? Microsoft Windows ??????? ?? ????? ??? ???? ???DataGrid???????? ??? ??? ?? ?? ????????? ?? ?????? ???? ?? ??? ??? ???? ??? ????????? ???? ?? ??? ????????DataGrid???????? ???

??????????

????? ???? outlines ???????? ?????????, ??????????, ??????? ?????? ?? ?????? ??? ?? ???? ???:
  • Microsoft Visual Basic 2005 ?? Visual Basic ?? Microsoft .NET
?? ???? ????? ?? ?? ?? ????? ???? ?? ?????? ???:
  • Visual Basic ???????????? ?????????

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

???????? ?? ????? ???? ?? ??? ?? ?? ?? ???? ??? accessors ???? ?????? ??? ???? ?? ??? ?? ?? ????? ???? ?? ???? ?? ???? ??? ???? ???????? ??? ????, ????? ??????? ???????????? ?? ???? ??? ???????? ???? ???? ????? ???? ?? ??? ????? (???? ?? ?? ???? ????? ?? ??.) ???? parameterized constructor ?? ?????? ???? ??? ??, ????? ??? ???????? ???? ???
Public Class guitar
    Private m_make As String
    Private m_model As String
    Private m_year As Short

    Public Sub New(ByVal make, ByRef model, ByVal year)
        m_make = make
        m_model = model
        m_year = year
    End Sub
    Public Property make() As String
        Get
            Return m_make
        End Get
        Set(ByVal Value As String)
            m_make = Value
        End Set
    End Property
    
End Class
				

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

?????????? ?? ????? ?? ?????? ?? ?????? ?? ???ArrayList?? ????? ?? ???? ????::
  1. ????? ??ArrayList.
  2. ???? ?? ?????? ?????, ?? ?? ?????????? ?? ?????ArrayList.
Private al as New Arraylist()

al.Add(New guitar("Gibson", "Les Paul", 1958))
al.Add(New guitar("Fender", "Jazz Bass", 1964))
al.Add(New guitar("Guild", "Bluesbird", 1971))
				

ArrayList DataGrid ?? ?????

???? ???ArrayList????????? ?? ???? ???, ??? ???????? ??????? ???DataGrid???? ?? ??? ????????ArrayList. ??????? ???DataGridcontrol are populated based on the properties for which in-scope property accessors exist.
DataGrid1.DataSource = al
				

Provide a means to browse the ArrayList

?? ????? ?? ???? ???CurrencyManagerto browse through theArrayList. To do this, associateCurrencyManager?? ???BindingContextof the control (in this case, theArrayList).
Private cManager As CurrencyManager

cManager = CType(DataGrid1.BindingContext(al), CurrencyManager)
				
TheCurrencyManagerclass has a??????property that you can manipulate to iterate over the members of theArrayList. By adding to, or subtracting from, the current value of??????, you can browse the rows of theDataGrid???????? ???
'Move forward one element.
cManager.Position += 1
'Move back one element.
cManager.Position -= 1
'Move to the beginning.
cManager.Position = 0
'Move to the end.
cManager.Position = al.Count - 1
				

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

  1. In Visual Basic2005 or in Visual Basic .NET, create a new Windows Application project. Form1 ???????? ??? ?? ???? ??..
  2. ????? ????????????????? ??,????? ??????to add a class to the project.
  3. ????? ??? ?? Class1.vb ??? ??? ?? ???????????? ????:
    Public Class guitar
        Private m_make As String
        Private m_model As String
        Private m_year As Short
    
        Public Sub New(ByVal make, ByRef model, ByVal year)
            m_make = make
            m_model = model
            m_year = year
        End Sub
        Public Property make() As String
            Get
                Return m_make
            End Get
            Set(ByVal Value As String)
                m_make = Value
            End Set
        End Property
        Public Property model() As String
            Get
                Return m_model
            End Get
            Set(ByVal Value As String)
                m_model = Value
            End Set
        End Property
        Public Property year() As Short
            Get
                Return m_year
            End Get
            Set(ByVal Value As Short)
                m_year = Value
            End Set
        End Property
    End Class
    					
  4. Class1.vb ??? ????? ?? ??? ????, ?? ?? ??????? ??????? ?? ?????
  5. ????? ???DataGridForm1 ????????? ????? ????DataGrid??? ??????? ?? ????????? ?? ??? ???????? ???? ?? ??? ???????? ???
  6. ??? ?????????Form1 ?? ????????? ???? ??, ?? ???? ??? ??? ?? ??????? ??? ?? ????????? ?????
  7. ????????? ??????????? ?? ??? Button1 ?? ???next.
  8. ????????? ??????????? ?? ??? Button2 ?? ????????.
  9. ????????? ??????????? ?? ??? Button3 ?? ?????? ???..
  10. ????????? ??????????? ?? ??? Button4 ?? ????????.
  11. ????? ??? ??????Form1????:
    Private cManager As CurrencyManager
    Private al as New ArrayList()
    					
  12. ??? ????? ??? ???????Form1_Load?????:
    al.Add(New guitar("Gibson", "Les Paul", 1958))
    al.Add(New guitar("Fender", "Jazz Bass", 1964))
    al.Add(New guitar("Guild", "Bluesbird", 1971))
    				
    cManager = CType(DataGrid1.BindingContext(al), CurrencyManager)
    	
    DataGrid1.DataSource = al
    					
  13. ??? ??? ????? ??? ???????Form_Load?? ??? 1 ?? ??? ?? ????.:
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            cManager.Position += 1
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            cManager.Position -= 1
        End Sub
    
        Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            cManager.Position = 0
        End Sub
    
        Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
            cManager.Position = al.Count - 1
        End Sub
    					
  14. ?????, ?? ????????? ?? ??????
  15. ????????? ?? ??? ?? ???? ?? ??? ???? ??? ????? ????DataGrid???????? ??? ??? ???? ?? ?? ??????? ?? ???? ???????? ?? ??? ??? ??????

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

??? ?????? ???????? ?? ??? ?????? ?? ??? ??? ???? ???????? ?? ???????? ?? ??? ???? ???? ???? ??? (??????, ?????) accessors ?????? ???? ?? ???????? ?? ??? ???? ?? ???? ?????? ?? ?? ???? ???? ???? ???

?? ??? ????? ???? ?? ??? ???ArrayList?? ???????? ?? ???, ????? ????? ?? ???? ????:
  1. ?????? ?? ??? Class1.vb ???? ??????? ?? ??????? ?? ?????
    Public Class guitar
    '...
    End Class
    					
    ?????:
    Public Structure guitar
    '...
    End Structure
    					
  2. ????? ?? ?????? ????????? ?? ??? ?? ?????, ?? ??? ?? ??? ???? ?? ???? ???ArrayList?? ?????????

??????

???? ??????? ?? ???, Visual Studio .NET ?????? ??? ??? "Consumers ?? ???? ?? Windows ???????" ???? ?? ??????

???

???? ID: 316302 - ????? ???????: 04 ?????? 2010 - ??????: 2.0
???? ???? ???? ??:
  • Microsoft Visual Basic 2005
  • Microsoft Visual Basic .NET 2003 Standard Edition
  • Microsoft Visual Basic .NET 2002 Standard Edition
??????: 
kbvs2005swept kbvs2005applies kbhowtomaster kbmt KB316302 KbMthi
???? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:316302

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

 

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