Re: align to center the text in first column of listview
Set it via API.
Code:
Public Sub dbg_align()
Dim hHdr As Long
Dim HDI As HDITEMW
Dim cap As String
hHdr = SendMessage(hLVS, LVM_GETHEADER, 0&, ByVal 0&)
cap = "column 0"
HDI.Mask = HDI_FORMAT Or HDI_TEXT
HDI.fmt = HDF_STRING Or HDF_CENTER
HDI.cchTextMax = Len(cap)
HDI.pszText = StrPtr(cap)
Call SendMessage(hHdr, HDM_SETITEMW, 0&, HDI)
RedrawList
End Sub
Public Sub RedrawList()
Dim ct As Long
ct = SendMessage(hLVS, LVM_GETITEMCOUNT, 0&, ByVal 0&)
SendMessage hLVS, LVM_REDRAWITEMS, 0&, ByVal ct
UpdateWindow hLVS
End Sub
Re: align to center the text in first column of listview
Insert an invisible first column.......
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
Re: align to center the text in first column of listview
Like said before in dozens of other threads, use a MSFlexGrid.
The time you have spend on trying to bend the ListView in strange directions could also have been used on modifying your code once and for all.
Then all graphical/style effects would cost less than 10% of the time.
Re: align to center the text in first column of listview
[QUOTE=fafalone;5492856]Set it via API.
Code:
Public Sub dbg_align()
Dim hHdr As Long
Dim HDI As HDITEMW
Dim cap As String
hHdr = SendMessage(hLVS, LVM_GETHEADER, 0&, ByVal 0&)
cap = "column 0"
HDI.Mask = HDI_FORMAT Or HDI_TEXT
HDI.fmt = HDF_STRING Or HDF_CENTER
HDI.cchTextMax = Len(cap)
HDI.pszText = StrPtr(cap)
Call SendMessage(hHdr, HDM_SETITEMW, 0&, HDI)
RedrawList
End Sub
Public Sub RedrawList()
Dim ct As Long
ct = SendMessage(hLVS, LVM_GETITEMCOUNT, 0&, ByVal 0&)
SendMessage hLVS, LVM_REDRAWITEMS, 0&, ByVal ct
UpdateWindow hLVS
End Sub
Dim HDI As HDITEMW error here:user defined type not defined
Re: align to center the text in first column of listview
@fafalone or anyone really. Have you been able to center the listview items using APIs? I gave it a shot and can get the column header's caption centered, but not the listview items themselves. I think the workarounds work for API-created ListViews, but no joy with the ocxs. Maybe the API calls are a timing thing -- when/where to call them, before form_load, on form_load, after form_load? Personally, I didn't try all the different scenarios.
Insomnia is just a byproduct of, "It can't be done"
Re: align to center the text in first column of listview
Originally Posted by luca90
i cannot set the first column to center text!
Insert invisible first column.......
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
Re: align to center the text in first column of listview
Originally Posted by Zvoni
Insert invisible first column.......
Though that is the simplest option, may not be desired in many cases. Why?
-- user may be able to unhide the column by resizing it with the mouse
-- if allowing auto-label-editing, then entering edit mode of a listview item will affect the 'hidden' column and not the 1st visible column.
Insomnia is just a byproduct of, "It can't be done"
Re: align to center the text in first column of listview
Originally Posted by LaVolpe
@fafalone or anyone really. Have you been able to center the listview items using APIs? I gave it a shot and can get the column header's caption centered, but not the listview items themselves. I think the workarounds work for API-created ListViews, but no joy with the ocxs. Maybe the API calls are a timing thing -- when/where to call them, before form_load, on form_load, after form_load? Personally, I didn't try all the different scenarios.
Hmm hadn't considered that.
Tried with a manifested 5.0 LV and got odd effects. The items centered, but selecting it... the click would only be recognized if it was where the text would appear if it was left-aligned, then the text itself became left-aligned.
Re: align to center the text in first column of listview
Originally Posted by LaVolpe
Though that is the simplest option, may not be desired in many cases. Why?
-- user may be able to unhide the column by resizing it with the mouse
-- if allowing auto-label-editing, then entering edit mode of a listview item will affect the 'hidden' column and not the 1st visible column.
Everything true, but........
..... his problem, not our problem....
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
Re: align to center the text in first column of listview
I circumvented the issue on my VBCCR.ListView.
The trick is just when using LVM_INSERTCOLUMN to apply (for index 0 only; left first column) always LVCFMT_LEFT on insert and afterwards change it immediately to LVCFMT_RIGHT or LVCFMT_CENTER via LVM_SETCOLUMN, if necessary.
Re: align to center the text in first column of listview
Originally Posted by Krool
I circumvented the issue on my VBCCR.ListView.
The trick is just when using LVM_INSERTCOLUMN to apply (for index 0 only; left first column) always LVCFMT_LEFT on insert and afterwards change it immediately to LVCFMT_RIGHT or LVCFMT_CENTER via LVM_SETCOLUMN, if necessary.
I tried that, after reviewing your VBCCR code. Didn't work with the ocxs, even v5.0
If someone got this working correctly, sample code + screenshot would be useful.
Ugh. Did I try it without having columns defined in ocx properties page? Now I'm not sure. Maybe that's the key; don't predefine them rather create them at runtime with or without APIs?
Last edited by LaVolpe; Sep 9th, 2020 at 01:31 PM.
Insomnia is just a byproduct of, "It can't be done"