Home Forums WinForms controls Xceed Grid for WinForms Copying grid takes too long

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #15401 |

    I adapted this from one of the samples illustrating how to copy grid’s contents. My grid has 8000 rows and 30 columns. When I tried to copy it it took close to 30 minutes. Here’s the code selection:

    foreach (Row row in rl)
    {
    if (row is Xceed.Grid.DataRow)
    {
    foreach (Cell cell in ((CellRow)row).Cells)
    {
    if (cell.Visible)
    text += cell.Value.ToString() + “\t”;
    }

    text += Environment.NewLine;
    }
    }

    data.SetData(DataFormats.Text, text);

    Is there any way to optimize the operation?

    Imported from legacy forums. Posted by Natalie (had 1853 views)

    User (Old forums)
    Member
    Post count: 23064

    You should really use a StringBuilder instead of constantly appending strings. Like this:
    <pre>StringBuilder b = new StringBuilder();
    foreach(Row row in rl)
    {
    Xceed.Grid.DataRow dataRow = row as Xceed.Grid.DataRow;
    if (dataRow != null)
    {
    foreach(Cell cell in dataRow.Cells)
    {
    if (cell.Visible)
    b.Append(cell.Value.ToString() + “\t”);
    }
    b.AppendLine();
    }
    }
    data.SetData(DataFormats.Text, b.ToString());</pre>

    Imported from legacy forums. Posted by Tommy (had 2975 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.