Solved

Listview Indivual Column Colors

Posted on 2003-11-15
7
435 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now