Solved

Listview Indivual Column Colors

Posted on 2003-11-15
7
441 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

777 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