Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / September 2006

Tip: Looking for answers? Try searching our database.

ListView Groups

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peter Larsen [] - 14 Sep 2006 10:27 GMT
Hi,

How do i change the ForeColor (font color) of the groupnames in a ListView
control ??

Thank you in advance.

BR
Peter
Linda Liu [MSFT] - 15 Sep 2006 08:35 GMT
Hi Peter,

This is issue is a little complex. There's no such a property or method for
us to change the font color of the group in a ListView cotrol.

I think we maybe need to make use of some Win32 API to do this. I am
researching on this problem and will get it back to you ASAP.

I appreciate your patience.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Peter Larsen [] - 15 Sep 2006 10:13 GMT
Hi Linda and thank you - i'm looking forward to hear from you !!
Linda Liu [MSFT] - 18 Sep 2006 10:25 GMT
Hi Peter,

The default font color of the group headers in a listview is black. There's
no property or method in the ListView or ListViewGroup classes for us to
change the font color of the group headers. Handling the DrawItem event of
the listview is no use, because we could only redraw items but not group
headers by this means.

However, we could call the SendMessage Win32 API to send a
LVM_SETGROUPMETRICS message the listview control to sepcify what color the
group header is. The following is a sample.

using System.Runtime.InteropServices;

public class ListViewAPI
   {
       #region Constants for Listview-Messages
       public const int LVM_FIRST = 4096;
       public const int LVM_SETGROUPMETRICS = (LVM_FIRST + 155);
       #endregion

       #region Constants for LVGROUPMETRICS.mask
       public const int LVGMF_NONE = 0;
       public const int LVGMF_BORDERSIZE = 1;
       public const int LVGMF_BORDERCOLOR = 2;
       public const int LVGMF_TEXTCOLOR = 4;
       #endregion

       [StructLayout(LayoutKind.Sequential)]
       public struct LVGROUPMETRICS
       {
           public int cbSize;
           public int mask;
           public int Left;
           public int Top;
           public int Right;
           public int Bottom;
           public int crLeft;
           public int crTop;
           public int crRight;
           public int crBottom;
           public int crHeader;
           public int crFooter;
       }

       [DllImport("User32.dll")]
       public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int
wParam, ref LVGROUPMETRICS lParam);

       public static void SetGroupHeaderColor(IntPtr handle, int color)
       {
           ListViewAPI.LVGROUPMETRICS groupMetrics;
           groupMetrics = new ListViewAPI.LVGROUPMETRICS();
           groupMetrics.cbSize =
Marshal.SizeOf(typeof(ListViewAPI.LVGROUPMETRICS));
          // set the mask to LVGMF_TEXTCOLOR to enable the new header
color to take effect
           groupMetrics.mask = ListViewAPI.LVGMF_TEXTCOLOR;
           groupMetrics.crHeader = color;            
           int ptrRetVal = (int)SendMessage(handle,
ListViewAPI.LVM_SETGROUPMETRICS, 0, ref groupMetrics);
       }
   }

private void Form1_Load(object sender, EventArgs e)
   {
ListViewAPI.SetGroupHeaderColor(this.listView1.Handle,0x0000ff00);
 }

Hope this helps.
If you have anything unclear, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support
Peter Larsen [] - 25 Sep 2006 08:05 GMT
Hi Linda,

This works just fine.
Thank you.

BR
Peter

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.