PC Review


Reply
Thread Tools Rate Thread

add images to virtual list

 
 
Anushya
Guest
Posts: n/a
 
      28th Dec 2003
Hi
I am trying to add image items to listview. Here how to handle if i
need to add images?? Pls go thru the code.

In the form where i have used this virtualListView, have handled
QueryItemText.. And text alone is working fine..

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);
}
}
}
}
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Backing up images in Virtual PC 2007 AMMN Windows Vista General Discussion 7 24th Mar 2008 05:54 AM
Images Virtual Directory Kevin.Ailes@gmail.com Microsoft ASP .NET 0 13th Mar 2007 03:36 PM
Pure Virtual Function Call when downloading images =?Utf-8?B?R2F2aW4gUm9iZXJ0cw==?= Microsoft Outlook Discussion 0 15th May 2006 01:26 PM
using ~ (virtual path) with images Brian Henry Microsoft ASP .NET 12 14th Apr 2004 02:09 AM
Duplicate IP Addresses on Virtual PC images Anthony P Windows XP New Users 1 11th Feb 2004 07:51 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:48 PM.