C
Carlos Carvalho
Hello there,
I need to make the listview controls accept image on subitems. I´m
using the folowing code...
public const Int32 LVM_FIRST = 0x1000;
public const Int32 LVM_GETITEM = LVM_FIRST + 5;
public const Int32 LVM_SETITEM = LVM_FIRST + 6;
public const Int32 LVIF_TEXT = 0x0001;
public const Int32 LVIF_IMAGE = 0x0002;
public const Int32 LVIF_INDENT = 0x0003;
public const int LVW_FIRST = 0x1000;
public const int LVM_GETEXTENDEDLISTVIEWSTYLE = LVW_FIRST + 54;
public const int LVS_EX_GRIDLINES =0x00000001;
public const int LVS_EX_SUBITEMIMAGES =0x00000002;
public const int LVS_EX_CHECKBOXES =0x00000004;
public const int LVS_EX_TRACKSELECT =0x00000008;
public const int LVS_EX_HEADERDRAGDROP =0x00000010;
public const int LVS_EX_FULLROWSELECT =0x00000020; // applies to
report mode only
public const int LVS_EX_ONECLICKACTIVATE =0x00000040;
private const int GW_CHILD = 5;
private const int GW_HWNDNEXT = 2;
[DllImport("coredll.dll", EntryPoint="SendMessageW",
SetLastError=true, CallingConvention=CallingConvention.Winapi)]
static extern bool SendMessage(IntPtr hWnd, Int32 msg, Int32 wParam,
ref LV_ITEM lParam);
[StructLayoutAttribute(LayoutKind.Sequential)]
struct LV_ITEM
{
public UInt32 mask;
public Int32 iItem;
public Int32 iSubItem;
public UInt32 state;
public UInt32 stateMask;
public String pszText;
public Int32 cchTextMax;
public Int32 iImage;
public IntPtr lParam;
}
// I´m doing this to set style that accept image on subitems. This
works fine...
IntPtr Form_hWnd = FindWindow(null, this.Text);
IntPtr lvwWnd = listView1.GetHandle(Form_hWnd, listView1.Text);
SendMessage(lvwWnd, LVM_GETEXTENDEDLISTVIEWSTYLE, IntPtr.Zero,
(IntPtr)(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES |
LVS_EX_HEADERDRAGDROP ));
// Later i´m trying do this, but an error acours....
IntPtr Form_hWnd = OAKListView.FindWindow(null, this.Text);
IntPtr lvwWnd = listView1.LoadOAKListView(Form_hWnd, listView1.Text);
for(int x=0;x<=listView1.Items.Count;x++)
{
for(int I=0;I<listView1.Columns.Count;I++)
{
LV_ITEM lvi = new LV_ITEM();
StringBuilder teste = new StringBuilder("Icon", 10);
lvi.iItem = x;
lvi.mask = OAKListView.LVIF_IMAGE;
lvi.iSubItem = I;
lvi.state = 0;
lvi.stateMask = 0;
lvi.pszText = teste;
lvi.cchTextMax = 0;
lvi.iImage = 1;
lvi.lParam = IntPtr.Zero;
try
{
bool res = SendMessage(lvwWnd, LVM_SETITEM, 0, ref lvi);
if(res)
MessageBox.Show("Works fine...");
}
catch(System.Exception ex)
{
MessageBox.Show("Last WinAPI error No. was: " +
Marshal.GetLastWin32Error().ToString() + "\r\n" + ex.ToString());
return;
}
}
}
Someone have ideia what´s happend wrong...
Or have some code that do this that i want...
TIA
[]´s
Carlos Carvalho
I need to make the listview controls accept image on subitems. I´m
using the folowing code...
public const Int32 LVM_FIRST = 0x1000;
public const Int32 LVM_GETITEM = LVM_FIRST + 5;
public const Int32 LVM_SETITEM = LVM_FIRST + 6;
public const Int32 LVIF_TEXT = 0x0001;
public const Int32 LVIF_IMAGE = 0x0002;
public const Int32 LVIF_INDENT = 0x0003;
public const int LVW_FIRST = 0x1000;
public const int LVM_GETEXTENDEDLISTVIEWSTYLE = LVW_FIRST + 54;
public const int LVS_EX_GRIDLINES =0x00000001;
public const int LVS_EX_SUBITEMIMAGES =0x00000002;
public const int LVS_EX_CHECKBOXES =0x00000004;
public const int LVS_EX_TRACKSELECT =0x00000008;
public const int LVS_EX_HEADERDRAGDROP =0x00000010;
public const int LVS_EX_FULLROWSELECT =0x00000020; // applies to
report mode only
public const int LVS_EX_ONECLICKACTIVATE =0x00000040;
private const int GW_CHILD = 5;
private const int GW_HWNDNEXT = 2;
[DllImport("coredll.dll", EntryPoint="SendMessageW",
SetLastError=true, CallingConvention=CallingConvention.Winapi)]
static extern bool SendMessage(IntPtr hWnd, Int32 msg, Int32 wParam,
ref LV_ITEM lParam);
[StructLayoutAttribute(LayoutKind.Sequential)]
struct LV_ITEM
{
public UInt32 mask;
public Int32 iItem;
public Int32 iSubItem;
public UInt32 state;
public UInt32 stateMask;
public String pszText;
public Int32 cchTextMax;
public Int32 iImage;
public IntPtr lParam;
}
// I´m doing this to set style that accept image on subitems. This
works fine...
IntPtr Form_hWnd = FindWindow(null, this.Text);
IntPtr lvwWnd = listView1.GetHandle(Form_hWnd, listView1.Text);
SendMessage(lvwWnd, LVM_GETEXTENDEDLISTVIEWSTYLE, IntPtr.Zero,
(IntPtr)(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES |
LVS_EX_HEADERDRAGDROP ));
// Later i´m trying do this, but an error acours....
IntPtr Form_hWnd = OAKListView.FindWindow(null, this.Text);
IntPtr lvwWnd = listView1.LoadOAKListView(Form_hWnd, listView1.Text);
for(int x=0;x<=listView1.Items.Count;x++)
{
for(int I=0;I<listView1.Columns.Count;I++)
{
LV_ITEM lvi = new LV_ITEM();
StringBuilder teste = new StringBuilder("Icon", 10);
lvi.iItem = x;
lvi.mask = OAKListView.LVIF_IMAGE;
lvi.iSubItem = I;
lvi.state = 0;
lvi.stateMask = 0;
lvi.pszText = teste;
lvi.cchTextMax = 0;
lvi.iImage = 1;
lvi.lParam = IntPtr.Zero;
try
{
bool res = SendMessage(lvwWnd, LVM_SETITEM, 0, ref lvi);
if(res)
MessageBox.Show("Works fine...");
}
catch(System.Exception ex)
{
MessageBox.Show("Last WinAPI error No. was: " +
Marshal.GetLastWin32Error().ToString() + "\r\n" + ex.ToString());
return;
}
}
}
Someone have ideia what´s happend wrong...
Or have some code that do this that i want...
TIA
[]´s
Carlos Carvalho