Solved

Listview Indivual Column Colors

Posted on 2003-11-15
7
448 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Suggested Solutions

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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 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…

734 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