我有一个列表视图。我的主要目标是能够将 ListViewItems 复制到剪贴板,然后复制到 Excel。但我在阅读 ListView 单元格时遇到了麻烦。
要获得我使用的列:
var columnNames = new StringBuilder();
foreach (GridViewColumn column in ((GridView)(listViewSolution.View)).Columns)
{
columnNames.Append(column.Header + "\t");
}
现在我想添加行,但我只能访问第一列中的第一个单元格,而不是第二个或第三个......:
var stringBuilder = new StringBuilder();
for (int i = 0; i < listViewSolution.Items.Count; i++)
{
stringBuilder.Append("\n");
//foreach (GridViewColumn column in ((GridView)(listViewSolution.View)).Columns)
//{
//if (column.Header != null)
//{
ListViewItem myListBoxItem =
(ListViewItem)(listViewSolution.ItemContainerGenerator.ContainerFromIndex(0)); //= Index 0 -> First Row, First Cell; Index 1 = Second Row, First Cell; But do we get: Second Column, First Row????
stringBuilder.Append(myListBoxItem.Content.ToString() + "\t");
//}
//}
}
System.Windows.Clipboard.SetData(DataFormats.Text, columnNames.ToString() + stringBuilder.ToString());
帮助将不胜感激..