【问题标题】:how to get values from arraylist to Textbox如何从数组列表中获取值到文本框
【发布时间】:2016-09-21 06:29:56
【问题描述】:
ArrayList myArrayList = new ArrayList();
for (int i = 0; i <= dt.Rows.Count - 1; i++)
{
    for (int j = 0; j <= dt.Columns.Count - 1; j++)
    {
        myArrayList.Add(dt.Rows[i][j].ToString());
    }
}

我想向我存储在数组列表中的所有邮件 ID 发送邮件。如何将该总数组列表绑定到Textbox

【问题讨论】:

  • 你想只绑定ArrayList 还是绑定stringArrayList 表示也对你有用?

标签: c# .net winforms arraylist


【解决方案1】:

如果我正确理解您的问题,此代码可能会对您有所帮助

foreach(object item in myArrayList)
{
    TextBoxId.Text += item.ToString();
} 

或者你可以忘记你的arrayList,在table中循环时直接填充TextBox。

          for (int i = 0; i <= dt.Rows.Count - 1; i++)
                 {
                     for (int j = 0; j <= dt.Columns.Count - 1; j++)
                     {
                         //myArrayList.Add(dt.Rows[i][j].ToString());
                         TextBoxId.Text += dt.Rows[i][j].ToString();
                     }
                 }

【讨论】:

    【解决方案2】:
    ArrayList myArrayList = new ArrayList();
    
    for (int i = 0; i <= dt.Rows.Count - 1; i++)
    {
        for (int j = 0; j <= dt.Columns.Count - 1; j++)
        {
            myArrayList.Add(dt.Rows[i][j].ToString());
        }
    }
    
    StringBuilder strb = new StringBuilder();
    
    foreach (var item in myArrayList)
    {
        strb.Append(item + ";");
    }
    

    您可以将strb.ToString() 绑定到您的文本框,或者您可以直接将DataTable 中的电子邮件ID 附加到StringBuilder 并将其绑定到您的文本框,而不是创建ArrayList

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多