C#将通用列表绑定到文本框WinForms? [英] C# Bind Generic List To Textbox WinForms?

查看:172
本文介绍了C#将通用列表绑定到文本框WinForms?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个方法返回一个字符串类型的列表。我想将列表中的每个项目绑定到文本框,因此基本上它看起来像一个列表框,除了它可以编辑,因为它实际上是一个文本框!



任何想法如何要执行此操作?



代码:

  public List< ;字符串> GetAgentsDetails(string writeDir)
{
列表< string> agentInfoList = new列表< string>();

XElement doc = XElement.Load(writeDir);

var getDetails =
(来自doc.Elements(Agent)中的n
选择n.Element(Name)。Value +,+ n.Element (EmailAddress)。
foreach(var info in getDetails)
{
agentInfoList.Add(info);
}
return agentInfoList;

}


解决方案

从我的头顶:

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

您的TextBox应该是多行的。


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.

这篇关于C#将通用列表绑定到文本框WinForms?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆