troubleshooting Question

Copy Datarows to clipboard in a nice format

Avatar of sandya_116
sandya_116 asked on
Visual Basic.NET
28 Comments1 Solution4290 ViewsLast Modified:
I am using the following code to copy datatable rows into clipboard:
Dim MyDataTable As New DataTable
                Dim MyRow As DataRow
                Dim MyColumn As DataColumn
                Dim TheString As New StringBuilder
                MyDataTable = MyTable
                TheString.Append("")
                For Each MyColumn In MyDataTable.Columns
                    TheString.Append(MyColumn.ColumnName & vbTab)
                Next MyColumn
                TheString.Remove(TheString.Length - 1, 1)
                TheString.Append(vbCr)
                For Each MyRow In MyDataTable.Rows
                    For Each MyColumn In MyDataTable.Columns
                        TheString.Append(MyRow(MyColumn) & vbTab)
                    Next MyColumn
                    TheString.Remove(TheString.Length - 1, 1)
                    TheString.Append(vbCr)
                Next MyRow
                Clipboard.SetDataObject(TheString.ToString)
The code above copies the rows to clipboard but the format is all messed up. The columns and rows don't line up. The reason I need it in a good format is because user pastes the text in an email. How can I make the columns and rows line up. Thanks.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 28 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 28 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros