我在表单中添加了RichTextBox
控件。我想在ArrayList
的{{1}}中显示数据。我怎么能这样做?
RichTextBox
答案 0 :(得分:0)
我认为只要ArrayList中的对象是简单数据类型,您就可以尝试
try
{
string filepath = "";
string filename = "";
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "XML files|*.xml";
if (ofd.ShowDialog() == DialogResult.OK)
{
filepath = ofd.FileName;
txtPath.Text = filepath + filename;
XMLParser objxmlparser = new XMLParser();
ArrayList al =objxmlparser.readDataLogXml(txtPath.Text);
for (int i = 0; i < al.Count; i++)
{
yourRichTextBox.Text += string.Format("{0}\r\n", al[i].ToString());
}
}
}
否则,如果ArrayList中的对象是您创建的自定义对象,则需要覆盖您定义的自定义类中的ToString()方法
public class YourCustomClass
{
// Your Custom Fields
// Your Custom Methods
public override string ToString()
{
// Format how you want this object to display information about itself
// The {0}, {1}, etc... are place holders for your custom fields
return string.Format("Put what you want to display here: {0} {1} {2}", customField1, customField2, customField3)
}
}