我遇到了RadListView为的WinForms一个很奇怪的现象,当我需要创建一个列表视图的单元格中的进度条。 它最初产生细胞进度条,但是当我向左滚动列表视图,右,进度条元素移动到左边一列。
这里是我的代码中插入创建进度条格:
_processingList = new RadListView();
_processingList.CellCreating += new ListViewCellElementCreatingEventHandler(_list_CellCreating);
_processingList.ViewType = ListViewType.DetailsView;
_processingList.Dock = System.Windows.Forms.DockStyle.Fill;
_processingList.HeaderHeight = 16;
_processingList.Columns.Add("Source");
_processingList.Columns.Add("Dir");
_processingList.Columns.Add("Destination");
_processingListProgressColumn = new ListViewDetailColumn("Progress", "");
_processingList.Columns.Add(_processingListProgressColumn);
_processingList.Columns.Add("Size");
_processingList.Columns.Add("Priority");
_processingList.Columns.Add("Status");
_processingList.Columns.Add("Start Time");
_processingList.Columns.Add("Elapsed");
_processingList.Columns.Add("Left");
...
void _list_CellCreating(object sender, ListViewCellElementCreatingEventArgs e)
{
DetailListViewDataCellElement dataCell = e.CellElement as DetailListViewDataCellElement;
if (dataCell != null && dataCell.Data == _processingListProgressColumn)
{
e.CellElement = new ProgressBarCellElement(dataCell.RowElement, dataCell.Data);
}
}
class ProgressBarCellElement : DetailListViewDataCellElement
{
private RadProgressBarElement progressBar;
public ProgressBarCellElement(DetailListViewVisualItem owner, ListViewDetailColumn column)
: base(owner, column)
{
}
protected override void CreateChildElements()
{
base.CreateChildElements();
this.progressBar = new RadProgressBarElement();
this.progressBar.StretchHorizontally = this.progressBar.StretchVertically = true;
this.Children.Add(this.progressBar);
}
public override void Synchronize()
{
base.Synchronize();
this.Text = "";
try
{
this.progressBar.Value1 = Convert.ToInt32(this.Row[this.column]);
}
catch { }
}
protected override Type ThemeEffectiveType
{
get
{
return base.ThemeEffectiveType;
}
}
}
有人可以有很好的解释或指向我如何创造一些细胞内与进度的RadListView的正确方法?
RadListView使用虚拟化其在细节细胞视图,因此像滚动操作过程中被重用细胞。 为了处理这种情况,你应该先指定哪一列你的细胞应该一起工作,也,你应该设置一个默认的小区的情况下休息。 下面是一个完整的例子:
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
InitializeComponent();
radListView1 = new RadListView();
radListView1.Parent = this;
this.Controls.SetChildIndex(radListView1, 0);
radListView1.CellCreating += new ListViewCellElementCreatingEventHandler(_list_CellCreating);
radListView1.ViewType = ListViewType.DetailsView;
radListView1.Dock = System.Windows.Forms.DockStyle.Fill;
radListView1.HeaderHeight = 16;
radListView1.Columns.Add("Source");
radListView1.Columns.Add("Dir");
radListView1.Columns.Add("Destination");
_processingListProgressColumn = new ListViewDetailColumn("Progress", "");
radListView1.Columns.Add(_processingListProgressColumn);
radListView1.Columns.Add("Size");
radListView1.Columns.Add("Priority");
radListView1.Columns.Add("Status");
radListView1.Columns.Add("Start Time");
radListView1.Columns.Add("Elapsed");
radListView1.Columns.Add("Left");
for (int i = 0; i < 60; i++)
{
radListView1.Items.Add("src", "dir", "dest", i * 1.14, "123", "high", "stat", "start", "elapsed", "left");
}
}
ListViewDetailColumn _processingListProgressColumn;
private void _list_CellCreating(object sender, ListViewCellElementCreatingEventArgs e)
{
DetailListViewDataCellElement dataCell = e.CellElement as DetailListViewDataCellElement;
if (dataCell != null)
{
if (dataCell.Data == _processingListProgressColumn)
{
e.CellElement = new ProgressBarCellElement(dataCell.RowElement, dataCell.Data);
}
else
{
e.CellElement = new DefaultCellElement(dataCell.RowElement, dataCell.Data);
}
}
}
class DefaultCellElement : DetailListViewDataCellElement
{
public DefaultCellElement(DetailListViewVisualItem owner, ListViewDetailColumn column) :
base(owner, column)
{
}
public override bool IsCompatible(ListViewDetailColumn data, object context)
{
return data.Name != "Progress";
}
protected override Type ThemeEffectiveType
{
get
{
return base.ThemeEffectiveType;
}
}
}
class ProgressBarCellElement : DetailListViewDataCellElement
{
private RadProgressBarElement progressBar;
public ProgressBarCellElement(DetailListViewVisualItem owner, ListViewDetailColumn column)
: base(owner, column)
{
}
public override bool IsCompatible(ListViewDetailColumn data, object context)
{
return data.Name == "Progress";
}
protected override void CreateChildElements()
{
base.CreateChildElements();
this.progressBar = new RadProgressBarElement();
this.progressBar.StretchHorizontally = this.progressBar.StretchVertically = true;
this.Children.Add(this.progressBar);
}
public override void Synchronize()
{
base.Synchronize();
this.Text = "";
try
{
this.progressBar.Value1 = Convert.ToInt32(this.Row[this.column]);
}
catch { }
}
protected override Type ThemeEffectiveType
{
get
{
return base.ThemeEffectiveType;
}
}
}
文章来源: RadListView has strange behavior when creating custom cell element with progressbar