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

时间:2021-08-07 19:34:01

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 个解决方案

#1


From the top of my head:

从我的头顶:

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

Ofcourse your TextBox should be multiline.

当然你的TextBox应该是多行的。

#1


From the top of my head:

从我的头顶:

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

Ofcourse your TextBox should be multiline.

当然你的TextBox应该是多行的。