ListView Icons not being removed. Display in another way?
I've got a ListView with several columns. The ListView's SmallImageList contains three icons; an up-arrow, a down-arrow and a folder icon. When one of the column-headers is clicked, the list is sorted by that value, and to illustrate this, an icon is inserted into the header showing the up or downarrow from its SmallImageList. This works fine.
My problem is that when clicking on a new开发者_运维百科 column to sort by, the icon in the old header should dissapear, but it doesn't. Instead, a folder-icon is inserted. This happens each time a new header is clicked, so eventually all headers are filled with folder-icons.
Whenever a column is clicked, all the columns are iterated through and their ImageKey is set to an empty string, and later replaced by the ImageKey for the arrows, if it was the clicked column. The empty string apparantly loads the folder icon.
for (int i = 0; i < m_LVCases.Columns.Count; i++)
{
m_LVCases.Columns[i].ImageKey = "";
if (i == e.Column)
{
if (m_ListViewColumnSorter.Order == SortOrder.Ascending)
m_LVCases.Columns[i].ImageKey = SortOrder.Ascending.ToString();
else if (m_ListViewColumnSorter.Order == SortOrder.Descending)
m_LVCases.Columns[i].ImageKey = SortOrder.Descending.ToString();
}
}
I can't post screenshots yet, as I don't have enough reputation. Does anybody have a solution to completely remove an icon from a column-header, or do I have to do some magic to display this in another way?
--Edit-- This is a project that I took over, so I'm trying to piece things together. I found out that setting the ImageKey for the column to null
, resulted in all the headers (except the one clicked) got the folder icon, which is very strange to me. I tried adding a new icon, with only transparent color on it. This did in fact clear all the icons, but it left a gap where the icon should have been. Is there a way to place the icon-allignment to the right instead, so it won't move the header text for every column?
There's a pretty clean example of this in the MSDN reference here
What you're doing is very different, but what might help you is to set the .visible property of the column sortimage to false for the other columns.
I fixed the problem myself. I was trying to place the icons to the right of the text instead, but by setting the column's TextAlign property to anything just after havning cleared the imageKey, the folder-icons stopped appearing.
So I removed the symptoms, but I still don't know what the disease was.
精彩评论