问题: TextBox1 输出为空白的,以下为代码。请帮忙解决一下
Dim locations As New List(Of Location)
For i As Integer = 0 To 20
Dim loc As New Location()
loc.ID = "ID" & i.ToString
loc.Name = "测试"
loc.X = "x"
loc.Y = "y"
loc.Ismain = False
locations.Add(loc) Next
For Each v As Location In locations
Me.TextBox1.AppendText(v.ID & v.Name & vbCrLf)
Next
对象Location Public Class Location Private _id As String
Public Property ID() As String
Get
Return _id End Get
Set(ByVal value As String)
value = _id End Set
End Property Private _name As String
Public Property Name() As String
Get
Return _name End Get
Set(ByVal value As String)
value = _name End Set
End Property Private _isMain As Boolean
Public Property Ismain() As Boolean
Get
Return _isMain End Get
Set(ByVal value As Boolean)
value = _isMain End Set
End Property Private _x As String
Public Property X() As String
Get
Return _x End Get
Set(ByVal value As String)
value = _x End Set
End Property Private _y As String
Public Property Y() As String
Get
Return _y End Get
Set(ByVal value As String)
value = _y End Set
End PropertyEnd Class
Dim locations As New List(Of Location)
For i As Integer = 0 To 20
Dim loc As New Location()
loc.ID = "ID" & i.ToString
loc.Name = "测试"
loc.X = "x"
loc.Y = "y"
loc.Ismain = False
locations.Add(loc) Next
For Each v As Location In locations
Me.TextBox1.AppendText(v.ID & v.Name & vbCrLf)
Next
对象Location Public Class Location Private _id As String
Public Property ID() As String
Get
Return _id End Get
Set(ByVal value As String)
value = _id End Set
End Property Private _name As String
Public Property Name() As String
Get
Return _name End Get
Set(ByVal value As String)
value = _name End Set
End Property Private _isMain As Boolean
Public Property Ismain() As Boolean
Get
Return _isMain End Get
Set(ByVal value As Boolean)
value = _isMain End Set
End Property Private _x As String
Public Property X() As String
Get
Return _x End Get
Set(ByVal value As String)
value = _x End Set
End Property Private _y As String
Public Property Y() As String
Get
Return _y End Get
Set(ByVal value As String)
value = _y End Set
End PropertyEnd Class
For Each v As Location In locations
MessageBox.Show(v.ID & v.Name & vbCrLf)
Next
试试
Dim locations As New List(Of Location)
For i As Integer = 0 To 20
Dim loc As New Location()
loc.ID = "ID" & i.ToString
loc.Name = "测试"
loc.X = "x"
loc.Y = "y"
loc.Ismain = False
locations.Add(loc) Next
For Each v As Location In locations
Me.TextBox1.AppendText(v.ID & v.Name & vbCrLf)
Next
放在什么地方了??打断点看看有没有执行??如果执行了,在查找所有对TextBox1赋值的地方是否是执行后又被赋了空值。
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim locations As New List(Of Location) For i As Integer = 0 To 20
Dim loc As New Location()
loc.ID = "ID" & i.ToString
loc.Name = "测试"
loc.X = "x"
loc.Y = "y"
loc.Ismain = False
locations.Add(loc) Next For Each v As Location In locations
Me.TextBox1.AppendText("oo" & v.ID & v.Name & vbCrLf)
Next End Sub
End Class
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication74
{
public class Location
{
String _id;
public String ID
{
get
{
return _id;
}
set
{
_id = value;
}
} String _name;
public String Name
{
get
{
return _name;
}
set
{
_name = value;
}
} bool _isMain;
public bool Ismain
{
get
{
return _isMain;
}
set
{
_isMain = value;
}
} String _x;
public String X
{
get
{
return _x;
}
set
{
_x = value;
}
} String _y;
public String Y
{
get
{
return _y;
}
set
{
_y = value;
}
}
} public partial class Form1 : Form
{
public Form1()
{
InitializeComponent(); TextBox TextBox1 = new TextBox();
TextBox1.Multiline = true;
TextBox1.Height = 100;
TextBox1.Parent = this; List<Location> locations = new List<Location>(); for (int i = 0; i <= 20; i++)
{
Location loc = new Location();
loc.ID = "ID" + i.ToString();
loc.Name = "测试";
loc.X = "x";
loc.Y = "y";
loc.Ismain = false;
locations.Add(loc);
} foreach (Location v in locations)
TextBox1.AppendText(v.ID + v.Name + Environment.NewLine);
}
}
}value=...
你写反了
Set(ByVal value As String)
value = _name End Set应该是 Set(ByVal value As String)
_name = value End Set