C# Bind Generic List To Textbox WinForms?

孤人 提交于 2019-12-13 05:08:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!