【问题标题】:how do i print the contents of a gridview to a textbox如何将gridview的内容打印到文本框
【发布时间】:2020-08-20 17:02:07
【问题描述】:

我想将GridView 的内容输出到TextBox,并且每一行都有自己的行。这就是我现在所拥有的,但它只将第一行输出到 TextBox

for (int i = 0; i < POSDGV.Rows.Count; ++i)
{
    string Item = POSDGV.Rows[i].Cells[0].Value.ToString();
    string Amount = POSDGV.Rows[i].Cells[1].Value.ToString();
    string Receipt = Item + " " + Amount;
    Receipttxt.Text = Receipt + "\n";
}

感谢帮助

【问题讨论】:

  • 你可以试试i++
  • 还是不行,i++和++i是一回事
  • 你需要做Receipttxt.Text += Receipt + "\n";
  • i++ and ++i are the same thing...这取决于上下文。
  • 不要拨打DataGridViewa GridViewDataGrid,反之亦然!!这是错误的和令人困惑的,因为它们是不同的控件。总是用正确的名字来称呼事物!

标签: c#


【解决方案1】:

取决于技术,但对于 Windows.Forms,您可以使用 Multiline 属性:https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.textbox.multiline?view=netcore-3.1

在此处查看此答案 How to add a line to a multiline TextBox? 以获取示例。值得注意的是事件方法:

public static class WinFormsExtensions
{
   public static void AppendLine(this TextBox source, string value)
   {
      if (source.Text.Length==0)
         source.Text = value;
      else
         source.AppendText("\r\n"+value);
   }
}

【讨论】:

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