Beispiel #1
0
 public static String ListViewToString(ListView copythis, ListViewStringConstants lvsc)
 {
     return ListViewToString(copythis, lvsc, ",", Environment.NewLine,"Group");
 }
Beispiel #2
0
        public static String ListViewToString(ListView copythis, ListViewStringConstants lvsc,String columnseparator,String rowseparator,String GroupColumnName)
        {
            StringBuilder sbuild = new StringBuilder();

            if (copythis.ShowGroups)
            {

                sbuild.Append(GroupColumnName + ",");

            }
            //step one: copy columnheaders
            foreach (ColumnHeader itheader in copythis.Columns)
            {

                sbuild.Append(itheader.Text.Trim());
                sbuild.Append(columnseparator);

            }
            foreach (ListViewItem iterateitem in copythis.Items)
            {
                sbuild.Append(rowseparator);
                if (iterateitem.Group != null)
                    sbuild.Append(iterateitem.Group.Header + ",");
                foreach (ListViewItem.ListViewSubItem loopsubitem in iterateitem.SubItems)
                {

                    sbuild.Append(loopsubitem.Text);
                    sbuild.Append(columnseparator);

                }

            }
            String madestring = sbuild.ToString();
            //remove trailing commas.
            madestring = madestring.Replace(columnseparator + rowseparator, rowseparator);
            //if HTML, we need to make some replacements.
            if (lvsc == ListViewStringConstants.Copy_HTMLFRAGMENT)
            {

                String nativeHTMLString =
            @"Version:0.9
            StartHTML:<<<<<<<1
            EndHTML:<<<<<<<2
            StartFragment:<<<<<<<3
            EndFragment:<<<<<<<4
            StartSelection:<<<<<<<3
            EndSelection:<<<<<<<4
            <!DOCTYPE>
            <html>
            <head>
            <title>HTML Copy paste from BCJobClock</title>
            </head>
            <body>
            <!-- StartFragment -->
            ";

                madestring = "<table><tr>" + madestring + "</tr></table>";
                madestring = madestring.Replace(Environment.NewLine, "</tr>" + rowseparator + "<tr>");
                madestring = madestring.Replace(columnseparator, "</td><td>");

                nativeHTMLString = nativeHTMLString + madestring +
                    @"<!-- EndFragment -->
            </body></html>";

                string utf8EncodedHTMLString = Encoding.GetEncoding(0).GetString(Encoding.UTF8.GetBytes(nativeHTMLString));

                StringBuilder sb = new StringBuilder();
                sb.Append(utf8EncodedHTMLString);
                sb.Replace("<<<<<<<1",
                (utf8EncodedHTMLString.IndexOf("<HTML>") + "<HTML>".Length).ToString("D8"));
                sb.Replace("<<<<<<<2",
                (utf8EncodedHTMLString.IndexOf("</HTML>")).ToString("D8"));
                sb.Replace("<<<<<<<3",
                (utf8EncodedHTMLString.IndexOf("<!--StartFragment -->") + "<!--StartFragment -->".Length).ToString("D8"));
                sb.Replace("<<<<<<<4",
                (utf8EncodedHTMLString.IndexOf("<!--EndFragment -->")).ToString("D8"));
                string clipboardString = sb.ToString();

                //Clipboard.SetText(clipboardString, TextDataFormat.Html);
                return clipboardString;

            }

            return madestring;
        }
Beispiel #3
0
 public static void ListViewToClipboard(ListView copythis,ListViewStringConstants lvsc)
 {
     Clipboard.SetText(ListViewToString(copythis,lvsc));
 }