By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,290 Members | 1,481 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,290 IT Pros & Developers. It's quick & easy.

headache with listview

P: n/a
Hi All
I used listview and tried to update it by using Addrange.
When the number of items is less, it works fine.. But I
need to update nearly 200,000 items and it hangs. Also i
need to add images to listview also(This is to list all
the items in my inbox, and want to give the user the feel
of outlook).

Since it hangs for even 1000 items in the inbox, i tried
to shift to virtual listview. But virtual listview
(extending listview) didnt let me to add images.. i am
pasting the code here. Can anyone pls help me to let 1)
IMAGES TO BE ADDED TO THIS CODE

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);
}
}
}
}
Also it's flickering.. I tried to prevent it by using
LockWindowUpdate. But still it flickers.
2) Wot can be done to avoid flickering???

Then tried to list only the page user scrolls to.. But
for this i could track scroll bar events, but when i
override and tried to look how it scrolls by displaying
messages, it scrolls differently.. I am pasting that code
tooooooo.... pls provide me some suggestion
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace CtrPagingListView
{

#region VirtualListView Delegates
public delegate void QueryItemTextHandler(int
item, int subItem, out string text);
public delegate void QueryItemImageHandler(int
item, int subItem, out string text );
public delegate void QueryItemIndentHandler(int
item, out int itemIndent);
#endregion

public class CtrPagingListView :
System.Windows.Forms.ListView

{

const int WM_HSCROLL = 0x0114;
const int WM_VSCROLL = 0x0115;
protected const int WM_KEYDOWN = 0x0100;
// windows key codes, not used any more
protected const int VK_LEFT = 0x0025;
protected const int VK_UP = 0x0026;
protected const int VK_RIGHT = 0x0027;
protected const int VK_DOWN = 0x0028;
public int i = 0;
private System.ComponentModel.Container
components = null;

// 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 CtrPagingListView()
{
View = View.Details;
Sorting = SortOrder.None;
// This call is required by the
Windows.Forms Form Designer.
//InitializeComponent();
// TODO: Add any initialization
after the InitComponent call

}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool
disposing )
{
if( disposing )
{
if( components != null )
components.Dispose
();
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support -
do not modify
/// the contents of this method with the
code editor.
/// </summary>
private void InitializeComponent()
{
//
// CtrPagingListView
//
this.Size = new
System.Drawing.Size(352, 192);

}
#endregion

protected override void WndProc(ref
System.Windows.Forms.Message msg)
{
////added from virtual listview
NMHDR nm1;
bool messageProcessed = false;
switch (msg.Msg)
{
case (int)
WindowsMessage.WM_REFLECT + (int)WindowsMessage.WM_NOTIFY:
nm1 = (NMHDR)
msg.GetLParam(typeof(NMHDR));
switch(nm1.code)
{
case (int)
ListViewNotices.LVN_GETDISPINFOW:

OnDispInfoNotice(ref msg, false);

messageProcessed = true;
break;
default:
break;
}
break;
default:
break;
}
if (!messageProcessed)
{
base.WndProc(ref msg);
}
////upto

int NUMLINES = 5000;

int numLinesPerpage = 10;

if(msg.Msg == WM_VSCROLL)
{
System.IntPtr param =
msg.WParam;
string str;
switch ((int)param)
{
case 7:

System.Windows.Forms.MessageBox.Show("SB_BOTTOM
message" + (NUMLINES - numLinesPerpage) + "to" +
(NUMLINES-1));
i =
NUMLINES - numLinesPerpage;
break;
case 0:

System.Windows.Forms.MessageBox.Show("SB_linwup
WM_HSCROLL message" + (i - 1) + " to " + (i +
numLinesPerpage - 1));
i = i - 1;
break;
case 1:

System.Windows.Forms.MessageBox.Show("SB_LINEdown
message" + (i + 1) + "to" + (i + numLinesPerpage + 1));

i = i + 1;
break;
case 2:

System.Windows.Forms.MessageBox.Show("SB_PAGEUP
message"+ (i-numLinesPerpage) + "to" + (i));
i = i-
numLinesPerpage;
break;
case 3:

System.Windows.Forms.MessageBox.Show("SB_PAGEDOWN
message" + (i+numLinesPerpage) + " to " +
(i+numLinesPerpage+numLinesPerpage));
i = i +
numLinesPerpage;
break;
case 5:

System.Windows.Forms.MessageBox.Show
("SB_THUMBTRACK message");
break;
}
}
base.WndProc(ref msg);

}


protected override void OnMouseUp
(MouseEventArgs e)
{

System.Windows.Forms.MessageBox.Show
("ONMOusedown" + e.X + " Delta " + e.Delta);

System.Windows.Forms.MessageBox.Show
("ONMOusedown" + e.Y);
base.OnMouseUp(e);
}

public override bool PreProcessMessage
(ref System.Windows.Forms.Message

msg)
{

//Convert key code to a .NET Keys
structure
// Convert key code to a .NET
Keys structure
Keys keyData = ((Keys) (int)
msg.WParam) | ModifierKeys;
Keys keyCode = ((Keys) (int)
msg.WParam);
int numLinesPerpage = 10;

// handle message
if (keyData == Keys.Next)
{

System.Windows.Forms.MessageBox.Show("next page"
+

i + "to" + (i +
numLinesPerpage));

i = i + numLinesPerpage;

}
else if (keyData == Keys.Prior)
{

System.Windows.Forms.MessageBox.Show("prev
message"

+ i + "to" + (i -
numLinesPerpage));

i = i - numLinesPerpage;

}
else if (keyData == Keys.Up)
{
System.Windows.Forms.MessageBox.Show("UP" +

i + "to" +( i -
1));
i = i - 1;

}
else if (keyData == Keys.Down)
{

System.Windows.Forms.MessageBox.Show("DOWN" + i +

"to" + (i + 1));
i = i + 1;
}
else if (keyData == Keys.Left)
{

System.Windows.Forms.MessageBox.Show("Left");

}
else if (keyData == Keys.Right)
{

System.Windows.Forms.MessageBox.Show("Right");

}
return base.PreProcessMessage(ref
msg);
}

////this part of code is added from virtual list view
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)
{

System.Windows.Forms.MessageBox.Show("Failed to
copy text name from client: " + e.ToString
(), "VirtualListView.OnDispInfoNotice");
}
}
}
}

if((info.item.mask & (uint)
ListViewItemMask.LVIF_IMAGE) > 0)
{
string imageIndex;
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);
}



}
}





Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
are you using Listview1.BeginUpdate() (before you add) and
Listview1.EndUpdate (and after your finished)

these 2 calls will speed up your code drastically and it should prevent it
from hanging.
"Anushya devi" <an*******@discussions.microsoft.com> wrote in message
news:02****************************@phx.gbl...
Hi All
I used listview and tried to update it by using Addrange.
When the number of items is less, it works fine.. But I
need to update nearly 200,000 items and it hangs. Also i
need to add images to listview also(This is to list all
the items in my inbox, and want to give the user the feel
of outlook).

Since it hangs for even 1000 items in the inbox, i tried
to shift to virtual listview. But virtual listview
(extending listview) didnt let me to add images.. i am
pasting the code here. Can anyone pls help me to let 1)
IMAGES TO BE ADDED TO THIS CODE

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);
}
}
}
}
Also it's flickering.. I tried to prevent it by using
LockWindowUpdate. But still it flickers.
2) Wot can be done to avoid flickering???

Then tried to list only the page user scrolls to.. But
for this i could track scroll bar events, but when i
override and tried to look how it scrolls by displaying
messages, it scrolls differently.. I am pasting that code
tooooooo.... pls provide me some suggestion
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace CtrPagingListView
{

#region VirtualListView Delegates
public delegate void QueryItemTextHandler(int
item, int subItem, out string text);
public delegate void QueryItemImageHandler(int
item, int subItem, out string text );
public delegate void QueryItemIndentHandler(int
item, out int itemIndent);
#endregion

public class CtrPagingListView :
System.Windows.Forms.ListView

{

const int WM_HSCROLL = 0x0114;
const int WM_VSCROLL = 0x0115;
protected const int WM_KEYDOWN = 0x0100;
// windows key codes, not used any more
protected const int VK_LEFT = 0x0025;
protected const int VK_UP = 0x0026;
protected const int VK_RIGHT = 0x0027;
protected const int VK_DOWN = 0x0028;
public int i = 0;
private System.ComponentModel.Container
components = null;

// 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 CtrPagingListView()
{
View = View.Details;
Sorting = SortOrder.None;
// This call is required by the
Windows.Forms Form Designer.
//InitializeComponent();
// TODO: Add any initialization
after the InitComponent call

}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool
disposing )
{
if( disposing )
{
if( components != null )
components.Dispose
();
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support -
do not modify
/// the contents of this method with the
code editor.
/// </summary>
private void InitializeComponent()
{
//
// CtrPagingListView
//
this.Size = new
System.Drawing.Size(352, 192);

}
#endregion

protected override void WndProc(ref
System.Windows.Forms.Message msg)
{
////added from virtual listview
NMHDR nm1;
bool messageProcessed = false;
switch (msg.Msg)
{
case (int)
WindowsMessage.WM_REFLECT + (int)WindowsMessage.WM_NOTIFY:
nm1 = (NMHDR)
msg.GetLParam(typeof(NMHDR));
switch(nm1.code)
{
case (int)
ListViewNotices.LVN_GETDISPINFOW:

OnDispInfoNotice(ref msg, false);

messageProcessed = true;
break;
default:
break;
}
break;
default:
break;
}
if (!messageProcessed)
{
base.WndProc(ref msg);
}
////upto

int NUMLINES = 5000;

int numLinesPerpage = 10;

if(msg.Msg == WM_VSCROLL)
{
System.IntPtr param =
msg.WParam;
string str;
switch ((int)param)
{
case 7:

System.Windows.Forms.MessageBox.Show("SB_BOTTOM
message" + (NUMLINES - numLinesPerpage) + "to" +
(NUMLINES-1));
i =
NUMLINES - numLinesPerpage;
break;
case 0:

System.Windows.Forms.MessageBox.Show("SB_linwup
WM_HSCROLL message" + (i - 1) + " to " + (i +
numLinesPerpage - 1));
i = i - 1;
break;
case 1:

System.Windows.Forms.MessageBox.Show("SB_LINEdown
message" + (i + 1) + "to" + (i + numLinesPerpage + 1));

i = i + 1;
break;
case 2:

System.Windows.Forms.MessageBox.Show("SB_PAGEUP
message"+ (i-numLinesPerpage) + "to" + (i));
i = i-
numLinesPerpage;
break;
case 3:

System.Windows.Forms.MessageBox.Show("SB_PAGEDOWN
message" + (i+numLinesPerpage) + " to " +
(i+numLinesPerpage+numLinesPerpage));
i = i +
numLinesPerpage;
break;
case 5:

System.Windows.Forms.MessageBox.Show
("SB_THUMBTRACK message");
break;
}
}
base.WndProc(ref msg);

}


protected override void OnMouseUp
(MouseEventArgs e)
{

System.Windows.Forms.MessageBox.Show
("ONMOusedown" + e.X + " Delta " + e.Delta);

System.Windows.Forms.MessageBox.Show
("ONMOusedown" + e.Y);
base.OnMouseUp(e);
}

public override bool PreProcessMessage
(ref System.Windows.Forms.Message

msg)
{

//Convert key code to a .NET Keys
structure
// Convert key code to a .NET
Keys structure
Keys keyData = ((Keys) (int)
msg.WParam) | ModifierKeys;
Keys keyCode = ((Keys) (int)
msg.WParam);
int numLinesPerpage = 10;

// handle message
if (keyData == Keys.Next)
{

System.Windows.Forms.MessageBox.Show("next page"
+

i + "to" + (i +
numLinesPerpage));

i = i + numLinesPerpage;

}
else if (keyData == Keys.Prior)
{

System.Windows.Forms.MessageBox.Show("prev
message"

+ i + "to" + (i -
numLinesPerpage));

i = i - numLinesPerpage;

}
else if (keyData == Keys.Up)
{
System.Windows.Forms.MessageBox.Show("UP" +

i + "to" +( i -
1));
i = i - 1;

}
else if (keyData == Keys.Down)
{

System.Windows.Forms.MessageBox.Show("DOWN" + i +

"to" + (i + 1));
i = i + 1;
}
else if (keyData == Keys.Left)
{

System.Windows.Forms.MessageBox.Show("Left");

}
else if (keyData == Keys.Right)
{

System.Windows.Forms.MessageBox.Show("Right");

}
return base.PreProcessMessage(ref
msg);
}

////this part of code is added from virtual list view
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)
{

System.Windows.Forms.MessageBox.Show("Failed to
copy text name from client: " + e.ToString
(), "VirtualListView.OnDispInfoNotice");
}
}
}
}

if((info.item.mask & (uint)
ListViewItemMask.LVIF_IMAGE) > 0)
{
string imageIndex;
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);
}



}
}




Nov 15 '05 #2

P: n/a
you could try my listview. It's not %100 compatible with the built in
listview but it should be able to handle the things you seem to need
to do.

http://www.glacialcomponents.com/gl.htm
Allen Anderson
http://www.glacialcomponents.com
mailto: allen@put my website url here.com

On Sun, 28 Dec 2003 05:36:17 -0800, "Anushya devi"
<an*******@discussions.microsoft.com> wrote:
Hi All
I used listview and tried to update it by using Addrange.
When the number of items is less, it works fine.. But I
need to update nearly 200,000 items and it hangs. Also i
need to add images to listview also(This is to list all
the items in my inbox, and want to give the user the feel
of outlook).

Since it hangs for even 1000 items in the inbox, i tried
to shift to virtual listview. But virtual listview
(extending listview) didnt let me to add images.. i am
pasting the code here. Can anyone pls help me to let 1)
IMAGES TO BE ADDED TO THIS CODE

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);
}
}
}
}
Also it's flickering.. I tried to prevent it by using
LockWindowUpdate. But still it flickers.
2) Wot can be done to avoid flickering???

Then tried to list only the page user scrolls to.. But
for this i could track scroll bar events, but when i
override and tried to look how it scrolls by displaying
messages, it scrolls differently.. I am pasting that code
tooooooo.... pls provide me some suggestion
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace CtrPagingListView
{

#region VirtualListView Delegates
public delegate void QueryItemTextHandler(int
item, int subItem, out string text);
public delegate void QueryItemImageHandler(int
item, int subItem, out string text );
public delegate void QueryItemIndentHandler(int
item, out int itemIndent);
#endregion

public class CtrPagingListView :
System.Windows.Forms.ListView

{

const int WM_HSCROLL = 0x0114;
const int WM_VSCROLL = 0x0115;
protected const int WM_KEYDOWN = 0x0100;
// windows key codes, not used any more
protected const int VK_LEFT = 0x0025;
protected const int VK_UP = 0x0026;
protected const int VK_RIGHT = 0x0027;
protected const int VK_DOWN = 0x0028;
public int i = 0;
private System.ComponentModel.Container
components = null;

// 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 CtrPagingListView()
{
View = View.Details;
Sorting = SortOrder.None;
// This call is required by the
Windows.Forms Form Designer.
//InitializeComponent();
// TODO: Add any initialization
after the InitComponent call

}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool
disposing )
{
if( disposing )
{
if( components != null )
components.Dispose
();
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support -
do not modify
/// the contents of this method with the
code editor.
/// </summary>
private void InitializeComponent()
{
//
// CtrPagingListView
//
this.Size = new
System.Drawing.Size(352, 192);

}
#endregion

protected override void WndProc(ref
System.Windows.Forms.Message msg)
{
////added from virtual listview
NMHDR nm1;
bool messageProcessed = false;
switch (msg.Msg)
{
case (int)
WindowsMessage.WM_REFLECT + (int)WindowsMessage.WM_NOTIFY:
nm1 = (NMHDR)
msg.GetLParam(typeof(NMHDR));
switch(nm1.code)
{
case (int)
ListViewNotices.LVN_GETDISPINFOW:

OnDispInfoNotice(ref msg, false);

messageProcessed = true;
break;
default:
break;
}
break;
default:
break;
}
if (!messageProcessed)
{
base.WndProc(ref msg);
}
////upto

int NUMLINES = 5000;

int numLinesPerpage = 10;

if(msg.Msg == WM_VSCROLL)
{
System.IntPtr param =
msg.WParam;
string str;
switch ((int)param)
{
case 7:

System.Windows.Forms.MessageBox.Show("SB_BOTTOM
message" + (NUMLINES - numLinesPerpage) + "to" +
(NUMLINES-1));
i =
NUMLINES - numLinesPerpage;
break;
case 0:

System.Windows.Forms.MessageBox.Show("SB_linwup
WM_HSCROLL message" + (i - 1) + " to " + (i +
numLinesPerpage - 1));
i = i - 1;
break;
case 1:

System.Windows.Forms.MessageBox.Show("SB_LINEdown
message" + (i + 1) + "to" + (i + numLinesPerpage + 1));

i = i + 1;
break;
case 2:

System.Windows.Forms.MessageBox.Show("SB_PAGEUP
message"+ (i-numLinesPerpage) + "to" + (i));
i = i-
numLinesPerpage;
break;
case 3:

System.Windows.Forms.MessageBox.Show("SB_PAGEDOWN
message" + (i+numLinesPerpage) + " to " +
(i+numLinesPerpage+numLinesPerpage));
i = i +
numLinesPerpage;
break;
case 5:

System.Windows.Forms.MessageBox.Show
("SB_THUMBTRACK message");
break;
}
}
base.WndProc(ref msg);

}


protected override void OnMouseUp
(MouseEventArgs e)
{

System.Windows.Forms.MessageBox.Show
("ONMOusedown" + e.X + " Delta " + e.Delta);

System.Windows.Forms.MessageBox.Show
("ONMOusedown" + e.Y);
base.OnMouseUp(e);
}

public override bool PreProcessMessage
(ref System.Windows.Forms.Message

msg)
{

//Convert key code to a .NET Keys
structure
// Convert key code to a .NET
Keys structure
Keys keyData = ((Keys) (int)
msg.WParam) | ModifierKeys;
Keys keyCode = ((Keys) (int)
msg.WParam);
int numLinesPerpage = 10;

// handle message
if (keyData == Keys.Next)
{

System.Windows.Forms.MessageBox.Show("next page"
+

i + "to" + (i +
numLinesPerpage));

i = i + numLinesPerpage;

}
else if (keyData == Keys.Prior)
{

System.Windows.Forms.MessageBox.Show("prev
message"

+ i + "to" + (i -
numLinesPerpage));

i = i - numLinesPerpage;

}
else if (keyData == Keys.Up)
{
System.Windows.Forms.MessageBox.Show("UP" +

i + "to" +( i -
1));
i = i - 1;

}
else if (keyData == Keys.Down)
{

System.Windows.Forms.MessageBox.Show("DOWN" + i +

"to" + (i + 1));
i = i + 1;
}
else if (keyData == Keys.Left)
{

System.Windows.Forms.MessageBox.Show("Left");

}
else if (keyData == Keys.Right)
{

System.Windows.Forms.MessageBox.Show("Right");

}
return base.PreProcessMessage(ref
msg);
}

////this part of code is added from virtual list view
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)
{

System.Windows.Forms.MessageBox.Show("Failed to
copy text name from client: " + e.ToString
(), "VirtualListView.OnDispInfoNotice");
}
}
}
}

if((info.item.mask & (uint)
ListViewItemMask.LVIF_IMAGE) > 0)
{
string imageIndex;
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);
}



}
}





Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.