Solved

Listview Indivual Column Colors

Posted on 2003-11-15
7
444 Views
Last Modified: 2010-05-01
Hello, Im trying to make it so in listview1 i can have a specfic line a specfied color.
0
Comment
Question by:clear100-com
  • 4
  • 2
7 Comments
 

Author Comment

by:clear100-com
ID: 9754784
An example of what im looking for is this: http://codeguru.earthweb.com/listview/row_color.shtml

However that is C++ code.
0
 

Author Comment

by:clear100-com
ID: 9754941
This is what im looking for, but what is subclassing?
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 9755943
listview1.listsubitem(1).forecolor = vbred
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 26

Expert Comment

by:EDDYKT
ID: 9756000

listview1.listsubitems(1).forecolor = vbred

where listview1 is listitem
0
 

Author Comment

by:clear100-com
ID: 9756669
No, im looking for the background....
0
 

Accepted Solution

by:
clear100-com earned 0 total points
ID: 9756690
OK, i figured it out, please do not post any more comments in this session:
modListViewColorize:
======================
Option Explicit
Public Enum ImageSizingTypes
   [sizeNone] = 0
   [sizeCheckBox]
   [sizeicon]
End Enum
Public Enum LedgerColours
  vbledgerWhite = &HF9FEFF
  vbLedgerGreen = &HD0FFCC
  vbLedgerYellow = &HE1FAFF
  vbLedgerRed = &HE1E1FF
  vbLedgerGrey = &HE0E0E0
  vbLedgerBeige = &HD9F2F7
  vbLedgerSoftWhite = &HF7F7F7
  vbledgerPureWhite = &HFFFFFF
End Enum
Public Const LVM_FIRST As Long = &H1000
Public Const LVM_SETCOLUMNWIDTH As Long = (LVM_FIRST + 30)
Public Const LVSCW_AUTOSIZE As Long = -1
Public Const LVSCW_AUTOSIZE_USEHEADER As Long = -2
Public Declare Function SendMessage Lib "user32" _
   Alias "SendMessageA" _
  (ByVal hwnd As Long, _
   ByVal wMsg As Long, _
   ByVal wParam As Long, _
   lParam As Any) As Long


Public Sub SetListViewLedger(lv As ListView, _
                              Bar1Color As LedgerColours, _
                              Bar2Color As LedgerColours, _
                              nSizingType As ImageSizingTypes, _
                              frm As Form, _
                              ListV As ListView, _
                              ImgL As ImageList, _
                              Pict As PictureBox)

   Dim iBarHeight  As Long
   Dim lBarWidth   As Long
   Dim diff        As Long
   Dim twipsy      As Long
   
   iBarHeight = 0
   lBarWidth = 0
   diff = 0
   
   On Local Error GoTo SetListViewColor_Error
   
   twipsy = Screen.TwipsPerPixelY
   
   If lv.View = lvwReport Then
   
     
      With lv
        .Picture = Nothing
        .Refresh
        .Visible = 1
        .PictureAlignment = lvwTile
        lBarWidth = .Width
      End With  ' lv
       
      With Pict
         .AutoRedraw = False
         .Picture = Nothing
         .BackColor = vbWhite
         .Height = 1
         .AutoRedraw = True
         .BorderStyle = vbBSNone
         .ScaleMode = vbTwips
         .Top = Form1.Top - 10000
         .Width = Screen.Width
         .Visible = False
         .Font = lv.Font
         
         With .Font
            .Bold = lv.Font.Bold
            .Charset = lv.Font.Charset
            .Italic = lv.Font.Italic
            .Name = lv.Font.Name
            .Strikethrough = lv.Font.Strikethrough
            .Underline = lv.Font.Underline
            .Weight = lv.Font.Weight
            .Size = lv.Font.Size
         End With
         iBarHeight = .TextHeight("W")
         Select Case nSizingType
            Case sizeNone:
               iBarHeight = iBarHeight + twipsy
               
            Case sizeCheckBox:
               If (iBarHeight \ twipsy) > 18 Then
                  iBarHeight = iBarHeight + twipsy
               Else
                  diff = 18 - (iBarHeight \ twipsy)
                  iBarHeight = iBarHeight + (diff * twipsy) + (twipsy * 1)
               End If
               
            Case sizeicon:
               diff = ImgL.ImageHeight - (iBarHeight \ twipsy)
               iBarHeight = iBarHeight + (diff * twipsy) + (twipsy * 1)
               
         End Select
     
         .Height = iBarHeight * 2
         .Width = lBarWidth
         Pict.Line (0, 0)-(lBarWidth, iBarHeight), Bar1Color, BF
         Pict.Line (0, iBarHeight)-(lBarWidth, iBarHeight * 2), Bar2Color, BF
     
         .AutoSize = True
         .Refresh
         
      End With
      lv.Refresh
      lv.Picture = Pict.Image
     
   Else
   
      lv.Picture = Nothing
       
   End If

SetListViewColor_Exit:
On Local Error GoTo 0
Exit Sub
   
SetListViewColor_Error:

   With lv
      .Picture = Nothing
      .Refresh
   End With
   
   Resume SetListViewColor_Exit
   
End Sub
Public Sub lvAutosizeControl(lv As ListView)

   Dim col2adjust As Long
 For col2adjust = 0 To lv.ColumnHeaders.Count - 1
   
      Call SendMessage(lv.hwnd, _
                       LVM_SETCOLUMNWIDTH, _
                       col2adjust, _
                       ByVal LVSCW_AUTOSIZE_USEHEADER)

   Next
   
   
End Sub
======================
form1:
======================

Private Sub Form_Load()
   Command1.Caption = "Text Only"
End Sub
Private Sub Command1_Click()
   With ListView1
    .ListItems.Add 1, , , , 1
    .ListItems(1).SubItems(1) = "test"
      .Visible = False
      .Checkboxes = False
      .FullRowSelect = True
      Call SetListViewLedger(ListView1, _
                             vbLedgerYellow, _
                             vbLedgerGrey, _
                             sizeicon, Me, ListView1, ImageList1, TestPicture)
      .Refresh
      .Visible = True
   End With
End Sub
=============


Found this info from: http://www.mvps.org/vbnet/code/comctl/lvledger.htm
Requesting to lock this question to refund points, but to keep fourm up...
0
 

Expert Comment

by:YensidMod
ID: 9759191
Question is PAQed and 20 points refunded.

YensidMod
Experts Exchange Moderator
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question