Hi Eric& Terry
i was using addrange only to add items.. Now disabled
sorting too.. Still it is slow..
then tried virtual list which adds only text by using
System.Runtime.InteropServices.Marshal.Copy(data, 0,
info.item.pszText, data.Length);
It was flickering and changed the above statement to
prevent updating.
LockWindowUpdate(base.Handle);
System.Runtime.InteropServices.Marshal.Copy(data,
0, info.item.pszText, data.Length);
LockWindowUpdate(IntPtr.Zero);
still its flickering
I want the soln to avoid flickering and also how to add
images to virtual listview.. pasting the code here.. Pls
let me know immediately...
using System;
using System.Windows.Forms;
using System.Diagnostics;
namespace Microsoft.Samples.VirtualListView
{
#region VirtualListView Delegates
public delegate void QueryItemTextHandler(int item,
int subItem, out string text);
public delegate void QueryItemImageHandler(int item,
int subItem, out int imageIndex);
public delegate void QueryItemIndentHandler(int item,
out int itemIndent);
#endregion
/// <summary>
/// Summary description for
VirtualListViewControl.
/// </summary>
public class VirtualListView : ListView {
// store the item count to prevent the call to
SendMessage(LVM_GETITEMCOUNT)
private int itemCount = 0;
public int ItemCount {
get { return itemCount; }
set {
itemCount = value;
int result;
result = WindowsFunction.SendMessage(
this.Handle,
(int)
ListViewMessages.LVM_SETITEMCOUNT,
itemCount,
0);
}
}
public VirtualListView ()
{
// virtual listviews must be Details or List
view with no sorting
View = View.Details;
Sorting = SortOrder.None;
}
protected override
System.Windows.Forms.CreateParams CreateParams {
get {
CreateParams cp = base.CreateParams;
// LVS_OWNERDATA style must be set when
the control is created
cp.Style |= (int)
ListViewStyles.LVS_OWNERDATA;
return cp;
}
}
public new System.Windows.Forms.View View {
get {
return new System.Windows.Forms.View();
}
set {
if (value == View.LargeIcon ||
value == View.SmallIcon) {
//throw new ArgumentException("Icon
views are invalid for virtual ListViews", "View");
}
base.View = value;
}
}
#region Display query callbacks
public event QueryItemTextHandler QueryItemText;
public event QueryItemImageHandler QueryItemImage;
public event QueryItemIndentHandler
QueryItemIndent;
#endregion
void OnDispInfoNotice(ref Message m, bool
useAnsi) {
LVDISPINFO info = (LVDISPINFO)m.GetLParam
(typeof(LVDISPINFO));
string lvtext = null;
if((info.item.mask & (uint)
ListViewItemMask.LVIF_TEXT) > 0) {
if (QueryItemText != null) {
QueryItemText(info.item.iItem,
info.item.iSubItem, out lvtext);
if (lvtext != null) {
try {
int maxIndex = Math.Min(info.item.cchTextMax-1,
lvtext.Length);
char[] data = new char[maxIndex+1];
lvtext.CopyTo(0, data, 0, lvtext.Length);
data[maxIndex] = '\0';
System.Runtime.InteropServices.Marshal.Copy(data,
0, info.item.pszText, data.Length);
}
catch (Exception e) {
Debug.WriteLine("Failed to
copy text name from client: " + e.ToString
(), "VirtualListView.OnDispInfoNotice");
}
}
}
}
if((info.item.mask & (uint)
ListViewItemMask.LVIF_IMAGE) > 0) {
int imageIndex = 0;
if (QueryItemImage != null) {
QueryItemImage(info.item.iItem,
info.item.iSubItem, out imageIndex);
}
info.item.iImage = imageIndex;
}
if ((info.item.mask & (uint)
ListViewItemMask.LVIF_INDENT) > 0) {
int itemIndent = 0;
if (QueryItemIndent != null) {
QueryItemIndent(info.item.iItem, out
itemIndent);
}
info.item.iIndent = itemIndent;
}
m.Result = new IntPtr(0);
}
protected override void WndProc(ref
System.Windows.Forms.Message m) {
NMHDR nm1;
bool messageProcessed = false;
switch (m.Msg) {
case (int)WindowsMessage.WM_REFLECT +
(int)WindowsMessage.WM_NOTIFY:
nm1 = (NMHDR) m.GetLParam(typeof
(NMHDR));
switch(nm1.code) {
case (int)
ListViewNotices.LVN_GETDISPINFOW:
OnDispInfoNotice(ref m,
false);
messageProcessed = true;
break;
default:
break;
}
break;
default:
break;
}
if (!messageProcessed) {
base.WndProc(ref m);
}
}
}
}
-----Original Message-----
yea, that makes sense, but AddRange doesnt do the Begin/End update like they
should...
public virtual void AddRange
(System.Windows.Forms.TreeNode[] nodes) {
TreeNode local0;
System.Windows.Forms.TreeNode[] local1;
int local2;
if (nodes == null)
throw new ArgumentNullException("nodes");
local1 = nodes;
local2 = 0;
while (local2 < (int) local1.Length) {
local0 = local1[local2];
this.Add(local0);
local2++;
}
}
so you'd normally call BeginUpdate() then AddRange() then EndUpdate()
Terry said:
I was under the impression that the AddRange also calls
BeginUpdate/EndUpdate. If you're adding them one at a time via Add, you
should call Begin/EndUpdate yourself to supress paints until you're done
adding items.
It is the following paragraph from the "BeginUpdate" docs that led me to
that.
"The preferred way to add items to a tree view control is to use the
AddRange method to add an array of tree node items to
a tree view.
However,EndUpdate method
whensimply calls Add()
forit's done, then you
canusing "AddRange()"
to
addand then listing
withpopulate cannot be
reducedeven in case of 2
lakhsthis with ListView. I
amhave it in memory
andto the listview. If
so