当我调整列的大小时,它不会使用更新的对齐方式重绘数据。我尝试过使无效、刷新和其他一些事情。没有任何效果。有谁知道解决方法?我还没有在 Windows 的单声道中尝试过这个。
要明白我的意思,请将这个控件放在一个表单上,然后在 Linux 的单声道中运行它:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
class MyListView : ListView
{
private readonly List<ListViewItem> items_ = new List<ListViewItem>();
public MyListView()
{
VirtualMode = true;
Columns.Add("Col 1");
Columns.Add("Col 2");
Columns.Add("Col 3");
Add(new ListViewItem(new[] { "a", "b", "c" }));
Add(new ListViewItem(new[] { "a", "b", "c" }));
Add(new ListViewItem(new[] { "a", "b", "c" }));
Add(new ListViewItem(new[] { "a", "b", "c" }));
Add(new ListViewItem(new[] { "a", "b", "c" }));
}
protected override void OnRetrieveVirtualItem(RetrieveVirtualItemEventArgs e)
{
e.Item = items_[e.ItemIndex];
base.OnRetrieveVirtualItem(e);
}
public void Add(ListViewItem item)
{
items_.Add(item);
VirtualListSize = items_.Count;
}
protected override void OnDrawColumnHeader(DrawListViewColumnHeaderEventArgs e)
{
e.DrawText();
base.OnDrawColumnHeader(e);
}
protected override void OnDrawSubItem(DrawListViewSubItemEventArgs e)
{
var text = ((ListViewItem.ListViewSubItem)e.SubItem).Text;
using (var brush = new SolidBrush(e.SubItem.ForeColor))
{
e.Graphics.DrawString(text, Font, brush, e.Bounds);
}
base.OnDrawSubItem(e);
}
protected override void OnColumnWidthChanged(ColumnWidthChangedEventArgs e)
{
base.OnColumnWidthChanged(e);
Invalidate(true); // Nope, that didn't work
Refresh(); // Nope, that didn't work
}
}