简体   繁体   English

C#将通用列表绑定到文本框WinForms?

[英]C# Bind Generic List To Textbox WinForms?

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;

    }

From the top of my head: 从我的头顶:

MyTextBox.Lines = GetAgentsDetails(writeDir).ToArray();

Ofcourse your TextBox should be multiline. 当然,您的TextBox应该是多行的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM