当前位置: 首页>>代码示例>>C#>>正文


C# ListView.ToString方法代码示例

本文整理汇总了C#中System.Windows.Forms.ListView.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# ListView.ToString方法的具体用法?C# ListView.ToString怎么用?C# ListView.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Forms.ListView的用法示例。


在下文中一共展示了ListView.ToString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExportToExcell

        /// <summary>
        /// Exports a listview to exvcell
        /// </summary>
        /// <param name="lvi">The ListView to export to Excel</param>
        /// <param name="saveName">The name that the excel file will be saved as</param>
        /// <returns>If the grid was successfully exported and file saved</returns>
        public static bool ExportToExcell(ListView lvi, string saveName)
        {
            lvToExport = lvi;
            string strExtension = ".xls";
            string fullname = "";
            if (lvToExport != null)
            {
                try
                {
                    saveName = checkFileExists(saveName, strExtension, pathExports);
                    fullname = pathExports + saveName + strExtension;
                    StreamWriter sw = new StreamWriter(fullname, false);
                    sw.AutoFlush = true;
                    for (int col = 0; col < lvToExport.Columns.Count; col++)
                    {
                        sw.Write(lvToExport.Columns[col].Text.ToString() + "\t");
                    }

                    int rowIndex = 1;
                    int row = 0;
                    string st1 = "";
                    for (row = 0; row < lvToExport.Items.Count; row++)
                    {
                        if (rowIndex <= lvToExport.Items.Count)
                            rowIndex++;
                        st1 = "\n";
                        for (int col = 0; col < lvToExport.Columns.Count; col++)
                        {
                            if (lvToExport.Items[row].SubItems[col].Text.ToString() == "")
                            {
                                st1 += "NULL" + lvToExport.Items[row].SubItems[col].Text.ToString();
                            }
                            else
                            {
                                st1 += lvToExport.Items[row].SubItems[col].Text.ToString();
                            }
                            st1 = st1 + "\t";
                        }
                        sw.Write(st1);
                        //sw.Flush();
                    }
                    sw.Close();
                    FileInfo fil = new FileInfo(fullname);
                    if (fil.Exists == true)
                    {
                        if (MessageBox.Show("Grid has been exported to file" + Environment.NewLine + fil.FullName + Environment.NewLine + "Do you want to open file now?", "Export To Excel", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            CCFBGlobal.openDocumentOutsideCCFB(fil.FullName);
                        }
                        return true;
                    }

                }
                catch (Exception ex)
                {
                    FileInfo file = new FileInfo(pathExports + saveName + strExtension);
                    appendErrorToErrorReport(lvToExport.ToString(), ex.GetBaseException().ToString());
                    MessageBox.Show("ERROR: Could not export the grid.", "Error",
                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }

            return true;
        }
开发者ID:ricsin19,项目名称:FoodReceipt,代码行数:70,代码来源:CCFBGlobal.cs


注:本文中的System.Windows.Forms.ListView.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。