本文整理汇总了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;
}