Re: Listview Column ReOrder
http://www.vbforums.com/attachment.p...id=47243&stc=1
Save some indication of the order in the Registry, a file, or a database.
Re: Listview Column ReOrder
In addition, have a look at the ColumnHeader.Position and
ColumnHeader.SubItemIndex properties
Re: Listview Column ReOrder
Hi Mr. M.,
Thank you for you response. But I was hoping for a reply with some code I could use as a beginning. Like your link, "VB - Color a row in a ListView".
With some source to examine, that covers how the form functions that I included in the attached illustration, I might be able to work out a solution for my needs.
Thank you again.
1 Attachment(s)
Re: Listview Column ReOrder
Okay here is a modified version of my app that you referred to. You will need to add the Northwind.mdb
Re: Listview Column ReOrder
Thank you Marty. This gives me a starting point. I've already added the Northwind database and I think I understand the basics. :bigyello:
Re: Listview Column ReOrder
I forgot to mention that all my changes are marked with 'NEW. Don't hesitate to ask if you have questions. When you have the answer you need in this thread you can help us by marking the thread as resolved. If you have JavaScript enabled you can do that by selecting the Mark Thread Resolved item from the Thread Tools menu. Otherwise please insert "[Resolved]" at the start of the Subject and select the green checkmark from the Post Icons. Also if someone has been particularly helpful you have the ability to affect their forum "reputation" by rating their post. Only those ratings that you give after you have 20 posts will actually count, but in all cases the person you rate will see your rating and know that you appreciate their help. BTW, no need to do it for me.
Re: Listview Column ReOrder
Hi Marty,
The information and code was a great start. I found an issue with the unload event, which is probably why you weren't happy with it. The code works fine the first time to save the re-ordered columns. But when you close the application the second time, the order reverts back to 123.
I know why this is happening, and I'm on the job of creating a solution. At least I have the basics to work with now. When I have something that works, I'll post it.
Private Sub Form_Unload(Cancel As Integer)
'NEW - Save the column order. (I'm not happy with this but it works.)
Dim strOrder As String
Dim intVal As Integer
intVal = 1
Do Until lvFind.ColumnHeaders(intVal).Position = 1
intVal = intVal + 1
Loop
strOrder = lvFind.ColumnHeaders(intVal).Index
intVal = 1
Do Until lvFind.ColumnHeaders(intVal).Position = 2
intVal = intVal + 1
Loop
strOrder = strOrder & lvFind.ColumnHeaders(intVal).Index
intVal = 1
Do Until lvFind.ColumnHeaders(intVal).Position = 3
intVal = intVal + 1
Loop
strOrder = strOrder & lvFind.ColumnHeaders(intVal).Index
SaveSetting "MyColumnPositionApp", "Column Positions", "MyListview", strOrder
Set frmFind = Nothing
End Sub
Re: Listview Column ReOrder
Okay I've got it.
Code:
Private Sub Form_Load()
' Create the instance of the database class
Set gDB = New CDatabase
' Open the database
gDB.dbName = App.Path & "\northwind.MDB"
'NEW - Get saved order. If there are none (1st run) then the default order is 123
mstrColumnPositions = GetSetting("MyColumnPositionApp", _
"Column Positions", "MyListview", "Product|Supplier ID|Category ID")
mstrColumnPositions = Replace(mstrColumnPositions, " ", "_")
Dim strParts() As String
strParts = Split(mstrColumnPositions, "|")
CallByName frmFind, strParts(0), VbMethod
CallByName frmFind, strParts(1), VbMethod
CallByName frmFind, strParts(2), VbMethod
lvFind.BorderStyle = ccFixedSingle ' Set BorderStyle property.
lvFind.View = lvwReport ' Set View property to Report.
' Label OptionButton controls with SortOrder options.
OptSort(0).Caption = "Sort Ascending"
OptSort(1).Caption = "Sort Descending"
lvFind.SortOrder = lvwAscending ' Sort ascending.
OptSort(0).Value = True
End Sub
Replace the Column1, etc subs with these.
Code:
Public Sub Product()
Dim clmX As ColumnHeader
Set clmX = lvFind.ColumnHeaders.Add(, , "Product", (lvFind.Width - 1066) / 2)
End Sub
Public Sub Supplier_ID()
Dim clmX As ColumnHeader
Set clmX = lvFind.ColumnHeaders.Add(, , "Supplier ID", (lvFind.Width - 1066) / 2)
End Sub
Public Sub Category_ID()
Dim clmX As ColumnHeader
Set clmX = lvFind.ColumnHeaders.Add(, , "Category ID", 976)
End Sub
Code:
Private Sub Form_Unload(Cancel As Integer)
Dim strOrder As String
Dim intVal As Integer
SaveSetting "MyColumnPositionApp", "Column Positions", "MyListview", _
lvFind.ColumnHeaders(lvFind.ColumnHeaders(1).Position).Text & "|" & _
lvFind.ColumnHeaders(lvFind.ColumnHeaders(2).Position).Text & "|" & _
lvFind.ColumnHeaders(lvFind.ColumnHeaders(3).Position).Text
Set frmFind = Nothing
End Sub
Re: Listview Column ReOrder
BTW, your registry will contain 123 or some variation of that order and in my new scheme you use the column header text so you'll have to override what is there the first time after you make these above changes. Just in case you don't know how to do that
- Put a breakpoint on the mstrColumnPositions = Replace(mstrColumnPositions, " ", "_") line
- In the Immediate Window type mstrColumnPositions = "Product|Supplier ID|Category ID" and press return.