ListView Control properties

  • Thread starter Thread starter Zahid
  • Start date Start date
Z

Zahid

Hi,

Im using a listView in my application. I want to be able
to set the background color of each item that I add to
the listview - rotating between 2 colors. How do I do
this? Any ideas? some of the properties are not working
in list view like backcolor.

Thanks in advance.
 
Thanks Maarten,

Im actually trying to add multiple columns to the
ListView, whereas i can only gather that their is only 1
column used in the example of the custom list box you
have given. How would I implement that?

Thanks in advance.
 
Hmmm, first of all let me tell you that I should better read your question.
I don't know how I mixed up a ListView control with a ListBox, since they
are two separate things. I have not tried setting background color items in
a ListView, but perhaps it is possible to use a MessageWindow class and send
your ListView different background colors with window messages like
LVM_SETBKCOLOR and LVM_SETTEXTBKCOLOR. I have to admit that I don't know if
you can individually select colors for each item or that they work for the
entire listview. Perhaps somebody else has an alternative or better idea.
 
Hi,

No problem about the misread. Where can I get info on
programming with the MessageWindow? Is that API stuff?
Im new to VB.Net programming so forgive me if its a
simple task.

Also, I'tl suit my purpose even if I can set one color in
the ListView - maybe the backcolor. Im just looking to
add color to the control as the rest of my app has color.

Thanks in advance.
 
I have played a little around with a ListView and here is the easiest way
for you to change background / foreground colors by means of P/Invoking to
the underlying Win32 ListView control. What you can do best is download the
WinAPI library from OpenNETCF.org (http://www.opennetcf.org/winapi.asp).
Amongst others it contains functions to P/Invoke into the native Win32 code
and that is what you need to change colors of your ListView. In a little
sample I created a simple ListView control and a button on a form. When the
button is clicked I want to change the backcolor of the ListView. I hope
that you get the idea, even though the sample is in C#, not in VB:

private void button1_Click(object sender, System.EventArgs e)

{

listView1.Capture = true; // The
first 3 statements are used to get the handle to the ListView window.

IntPtr hWnd = Win32Window.GetCapture();

listView1.Capture = false;

Win32Window.SendMessage(hWnd, (uint)ListViewMessage.LVM_SETBKCOLOR , 0,
0x00ff0000); // Once we have a Window handle, we can now send the
ListView messages, like this one to change the background color.

listView1.Invalidate();

}

}

public enum ListViewMessage: uint // These are the WIndows messages as
defined in commctrl.h to "talk" to the ListView

{

LVM_FIRST = 0x1000,

LVM_GETBKCOLOR = LVM_FIRST + 0,

LVM_SETBKCOLOR = LVM_FIRST + 1,

LVM_GETTEXTCOLOR = LVM_FIRST + 35,

LVM_SETTEXTCOLOR = LVM_FIRST + 36,

LVM_GETTEXTBKCOLOR = LVM_FIRST + 37,

LVM_SETTEXTBKCOLOR = LVM_FIRST + 38,

}
 
Hi Zahid,

You can find some examples of using the MessageWindow class here...

Learn how to use the .NET Compact Framework MessageWindow class to create a
NotifyIcon.
http://msdn.microsoft.com/library/en-us/dnnetcomp/html/messagewindow.asp

This QuickStart uses MessageWindow to send messages to the form when the
mouse pointer clicks in a custom control defined as a Rectangle structure or
when the mouse clicks in a Panel control.
http://samples.gotdotnet.com/quickstart/CompactFramework/doc/messagewindow.aspx

--
Geoff Schwab
Program Manager
Excell Data Corporation
http://msdn.com/mobility

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thanks Maarten,
Thanks Geoff,

Sorry but my C# is weak and ive only recently started
VB.NET so im finding it difficult to translate yor code
example. Do you know of any C# to VB.Net translators?
Anyone else translate it for me please?

Thanks in advance.
-----Original Message-----
I have played a little around with a ListView and here is the easiest way
for you to change background / foreground colors by means of P/Invoking to
the underlying Win32 ListView control. What you can do best is download the
WinAPI library from OpenNETCF.org (http://www.opennetcf.org/winapi.asp).
Amongst others it contains functions to P/Invoke into the native Win32 code
and that is what you need to change colors of your ListView. In a little
sample I created a simple ListView control and a button on a form. When the
button is clicked I want to change the backcolor of the ListView. I hope
that you get the idea, even though the sample is in C#, not in VB:

private void button1_Click(object sender, System.EventArgs e)

{

listView1.Capture =
true; // The
first 3 statements are used to get the handle to the ListView window.

IntPtr hWnd = Win32Window.GetCapture();

listView1.Capture = false;

Win32Window.SendMessage(hWnd, (uint)
ListViewMessage.LVM_SETBKCOLOR , 0,
 
Thanks again Maarten.

I just wanted to understand your code a little better.
Where you have set up those constants such as
LVM_SETBKCOLOR and LVM_SETTEXTBKCOLOR, are these
predefined elsewhere ? or are you setting then to your
liking? also, the &H values - are these preset? if so is
there a list of them that I can access because I want to
know which values correspond to which Item.

Thanks in advance.
 
The LVM_* constants are actually predefined windows messages. You can find
the definitions for these particular messages in a C header file called
commctrl.h. If you have let's say a PPC 2003 SDK installed on your system,
you can find that file under the following path: <root path of the
SDK>\POCKET PC 2003\Include\<processor>. So LVM_* are the exact names of the
windows messages as used by Microsoft, the &H values are the hexadecimal
values those constants represent. Once you have a handle to the ListView
control (e.g. using the Capture method I showed you), you basically can send
the control any message that starts with LVM_.
 
Back
Top