Solved

How do I center the icon in a ListVIEW subitem

Posted on 2010-08-31
20
589 Views
Last Modified: 2012-05-10
I have a workbook that I am using listView in. (see thread 26440417 It has the workbook.)
I have one where the data is being show with icon of a check or a red x. The way it loads is alignment is LEFT. I would like to CENTER it

I have seen referanced to where people have figured it out, BUT THEY DID NOT POST HOW!

Thanks
Bruce
0
Comment
Question by:Bruj
  • 9
  • 7
  • 4
20 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
Why not simply post the link like this:
http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q__26440417.html

I don't understand what you are asking for?

Can you post a screenshot of what it looks like now, then post an image of what you want it to look like?
<I have seen referanced to where people have figured it out>
Can you point us to one of these "References" (by providing a link)?

Thanks

JeffCoachman
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
Why not simply post the link like this:
http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q__26440417.html

I don't understand what you are asking for?

Can you post a screenshot of what it looks like now, then post an image of what you want it to look like?
<I have seen referanced to where people have figured it out>
Can you point us to one of these "References" (by providing a link)?

Thanks

JeffCoachman
0
 
LVL 85

Expert Comment

by:Rory Archibald
Comment Utility
To the best of my knowledge, you can't because the icon area is fixed to the left of the text area.
0
 

Author Comment

by:Bruj
Comment Utility
This question has more or less migrated to another question that was started on a different subject. We are now trying to work on the centering issue at:http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Q_26440417.html
I HAVE found a _VB_ solution, but I am not sure how to convert it to VBA....
It also uses a third party addin for some of the functionality. I would want to use only default windows/offices references as our system ar work are locked down and I cannot get IS to add things with out TOTAL buy off oof management
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
No offense, but are you sure this is worth the trouble?

In other words, where have you seen this functionality before, that you need it duplicated?

JeffCoachman
0
 

Author Comment

by:Bruj
Comment Utility
It is for what I am trying to do. It is looking VERY sloppy otherwise.
I have whittle some code that I thinks should work, be, alas it does not...

Here is how I THINK it should work...

'code snippet:
        'test for moving icon
        numcnt = numcnt + 1
        Dim r1 As Variant
        Dim r2 As Point
        Dim r3 As Point

        t1 = SendMessageAny(ListView2.hWnd, Lvm_getitemposition, ListView2.ListItems(i - 1).ListSubItems(8).Index, r2)

        tf = MAKELPARAM(r2.x + 5000, r2.y + 2)
        t2 = SendMessageAny(ListView2.hWnd, Lvm_setitemposition, ListView2.ListItems(i - 1).ListSubItems(8).Index, tf)
        Dim u As Integer

      ' For u = 1 To 400 ' icon does not seem to move... is it a snap to grid issue?
        '    tf = MAKELPARAM(r2.x + u, r2.y + 2)
       ''     Debug.Print tf

         '   t1 = SendMessageAny(ListView2.hWnd, Lvm_getitemposition, ListView2.ListItems(i - 1).ListSubItems(8).Index, r3)
         '   t3 = SendMessageAny(ListView2.hWnd, Lvm_setitemposition, ListView2.ListItems(i - 1).ListSubItems(8).Index, tf)
         '   If r2.x <> r3.x Then
         '       Exit For
        '    End If
      ' Next
 



listviewSample2.xlsm
xmark.bmp
checkmark.bmp
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
Your workbook contains links and code references which I don't have, so I could not work on this.

I still am confused as to where you saw this functionality before?

Or are you asking us to try to do something for you that has never been done before?
I'm with rorya of this one.

Perhaps another Expert will be willing to help you further with this...

JeffCoachman
0
 

Author Comment

by:Bruj
Comment Utility
I habe seen several code segments that show you how to. The are written in either c or VB. Not the c code does not help much. but the VB has given me a lot to try...
There are still a few things I need to figure out though
http://www.weask.us/entry/center-subitem-icon-listview
http://vbnet.mvps.org/index.html?code/comctl/lvitemindent.htm
0
 
LVL 85

Expert Comment

by:Rory Archibald
Comment Utility
.net forms and VB forms are not the same as userforms, particularly as regards trying to get the handles of controls.
0
 

Author Comment

by:Bruj
Comment Utility
So... since we are using sendmessage, it should work, however, I may be getting the wrong hWnd and therefore trying to move the column in the wrong control...
Is there anyway I might be able to get the correct hWnd?
Also I am not sure about the index that I need to provide.
Thanks!
Bruce
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 85

Expert Comment

by:Rory Archibald
Comment Utility
I guess I should have been a lot more specific: controls on userforms are windowless - you can't get the handle.
0
 

Author Comment

by:Bruj
Comment Utility
oh.... So it cant be done??...
0
 
LVL 85

Expert Comment

by:Rory Archibald
Comment Utility
Actually, I've just done a quick test with Spy++ and it appears that the ListView control does have a window handle unlike the standard form controls.
0
 
LVL 85

Expert Comment

by:Rory Archibald
Comment Utility
Here's a sample of how to get the handle of a listview:


Private Declare Function FindWindowEx Lib "User32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long

Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long

Private Sub CommandButton1_Click()
    Dim hwndForm As Long, hwndLView As Long
    hwndForm = FindWindowEx(0&, 0&, vbNullString, Me.Caption)
    If hwndForm <> 0 Then
        hwndForm = FindWindowEx(hwndForm, 0&, "F3 Server 69630000", vbNullString)
        MsgBox hwndForm
        hwndLView = FindWindowEx(hwndForm, 0&, "ListView20WndClass", vbNullString)
        MsgBox hwndLView
    End If
End Sub

Open in new window

0
 

Author Comment

by:Bruj
Comment Utility
That would make sense as it is a COMMON CONTROL and not a excel object.
It appears that the listview1.hWnd returns the handle as well:)

Now, there seems to be 2 items that once I figure them out (or get shown the light...) That I should be able to do the centering!

The first is to find the "index" number of the cell, and then the get the correct lparam (I finally figure out that this varies with the call you are making to sendmessage!) So... I think I am half way there.

This "should" get current position
 Dim r2 As Point
Public Const Lvm_getitemposition As Integer = 4112
dim indx = ListView2.ListItems(i - 1).ListSubItems(8).Index
t2 = SendMessageAny(ListView2.hwnd, Lvm_getitemposition, indx, r2)
 and return them in r2

And the following should SET the position:
Public Const Lvm_setitemposition32 As Integer = 4145

 t2 = SendMessageAny(ListView2.hwnd, Lvm_setitemposition, indx, lparam)

I have been going crazy looking for the origianl source that I started monkeying around with!
But, it seems that the windows DESKTOP is a listview, so, if we can find any code changing icons locations, then that will help!
Again, I am finding things in VB and C.

Thanks!
0
 
LVL 85

Expert Comment

by:Rory Archibald
Comment Utility
The Lvm_getitemposition code will only work if your listview is in icon or smallicon view, which it isn't. Most of the other code you have referred to is .Net and as I said, those are different controls and forms.


0
 

Author Comment

by:Bruj
Comment Utility
rorya,
Just to verify, even though listview is a COMMON CONTROL, it would be accessed differently from under .net?

My reason I am asking this is that in the sites referred to, it is using desktop and stating it is a listview from the COMMON CONTROLs. And I thought that was what they are, COMMON, meaning shared by anything that uses them (and the way they are talked to)

Or, I be missunderstanding you. When you say "different controls" are you talking about the actual control or the mechanics to get to them (I am fairly ignorant with the newer stuff - Used to program dBase3/Foxbase etc....YEARS ago!) And the APIs...

So I am having a learning curve. Just I thought once you found on sendmessage, it would support all platforms the same as long as that control is available.

I am NOT trying to be disrespectfull in ANY way (just stubburn!) and I really do appreciate all the help!

Thanks

Bruce
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 250 total points
Comment Utility
Disclaimer: I am not in any way, shape or form (pardon the pun) a .Net expert.
There are huge differences in the way you interact with the controls in .Net, but that's not really the issue as regards your SendMessage code - as I said it will not work with a ListView in ReportView mode as yours is.
From a .Net perspective you have far more control over the drawing of your controls.

SO far, nothing you have shown me, and nothing I have found in my searches, indicates that you can do what you want in any environment, never mind in a VBA userform, but I wish you luck in your pursuit. :)

Rory
0
 

Author Comment

by:Bruj
Comment Utility
I FINALLY see the light!
OK, as I have been stating, the desktop (or any folderview) are listviews. This I knew!

I did not know what the ICON, SMALLICON, REPORT etc were!

This is where I was stuck!

Icon is when you have the icons on your folder showing, report is when you have either LIST or DETAILED view of a folder showing. Ofcourse you cannot move the POSITION of a FILENAME. DAH!!! I just did not make THAT anology!

It was not until I came across:http://www.java2s.com/Code/CSharp/GUI-Windows-Form/ListViewExample.htm (they do say a picture is worth a thousand words!) and SAW a listview with ICONS view that I realized what you were talking about (bloody ms has no visuals!)

So.... in a nut shell, aint gonna happen! (Like I said, I am stubburn!) And I DID keep coming across examples, I just did not know what they were talking about, yet I thought I did...
I HAVE been researching, so it was not just a matter of dumping a quest here and then waiting for the answer.

Now... To try to find that site that was talking about changing  FONTS on a subitem (and make sure I know what I am looking at<grin>) I hope that THAT was not in ICON mode only. Even though it probably was from what I am now seeing.


Thanks!
Bruce
0
 

Author Closing Comment

by:Bruj
Comment Utility
It was easy once I understood what I did not understand!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

771 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

11 Experts available now in Live!

Get 1:1 Help Now