首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

请教高手帮忙看下面vb.net的对象数组有关问题在哪

2012-03-22 
请问高手帮忙看下面vb.net的对象数组问题在哪。Public Class Form1Private BarProp() As ClsBarPropertyPri

请问高手帮忙看下面vb.net的对象数组问题在哪。
Public Class Form1
  Private BarProp() As ClsBarProperty
  Private BarPropNum As Integer = -1
  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

  End Sub

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  BarPropNum += 1
  ReDim BarProp(BarPropNum)
  BarProp(BarPropNum) = New ClsBarProperty()
  PropertyGrid1.SelectedObject = BarProp(BarPropNum)
  End Sub

  Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  PropertyGrid1.SelectedObject = BarProp(2)
  End Sub
End Class


[解决办法]
redim 之前 你要确保 BarPropNum >0

0的话 没意义

还有

 BarProp(BarPropNum) = New ClsBarProperty()

应该是

 BarProp(BarPropNum-1) = New ClsBarProperty()

热点排行