问题
I have a method that returns a list of type string. I want to bind each item in the list to the textbox so essentially it looks like a listbox, except it will be editable since its actually a textbox!
any ideas on how to go about doing this!?
CODE:
public List<string> GetAgentsDetails(string writeDir)
{
List<string> agentInfoList = new List<string>();
XElement doc = XElement.Load(writeDir);
var getDetails =
(from n in doc.Elements("Agent")
select n.Element("Name").Value + "," + n.Element("EmailAddress").Value);
foreach (var info in getDetails)
{
agentInfoList.Add(info);
}
return agentInfoList;
}
回答1:
From the top of my head:
MyTextBox.Lines = GetAgentsDetails(writeDir).ToArray();
Ofcourse your TextBox should be multiline.
来源:https://stackoverflow.com/questions/1078435/c-sharp-bind-generic-list-to-textbox-winforms