Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Sorting A Listview By Clicking Different Column Headers


I can't seem to find a way to sort a listview based on which column header is clicked. For instance when I click on a column header that is assigned to file names I want it to sort alphabetically, and when I click on a different column header I want it to sort by date. Another column header for time...

Can anyone help?

Thanks,
Bernie




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Sorting A ListView By Clicking Column...
I have a ListView with multiple columns. I have a text file that is read into the ListView and the contents of the file are split into each column. For example, in the file a line looks like 1,2,3 and the values are placed into their respective columns.
Also, one of the columns contains a filename, and if its detected, a checkmark is checked off. Fine so far. Problem I run into now, is how can I allow my users the ability to click on a column header and have the whole ListView sorted (either ascending or descending) based off of that row.
Tough ?

Thanks,

Problem With Flexgrid Column Headers When Sorting
I'm using Mendhak's column sort code with a flexgrid, however for some reason when the user selects a column to sort by, the first column drops its first two letters? So if my first column is called "SKU" when I sort the grid (any column) "SKU" becomes "U"?



Code:
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Dim strsql As String
Dim inti As Integer
Dim wasNull As Boolean
'On Error GoTo errhandler
With MSFItem
.Clear
.Rows = 2
Select Case Button.Key
Case "bmnSize"
.Clear
.Rows = 2
.Cols = 6
.FormatString = "^SKU |^QTY |^Size |^Color |^First Receive Date |^UPC "
strsql = "select a.sku_num, sum(a.avail_qty) qty, b.size_cd, b.color_des, b.first_rcv_dt, " & _
" d.upc_cd from gm_inv_loc a, gm_sku b, gm_itm c, gm_sku2upc_cd d" & _
" Where a.sku_num = b.sku_num And b.itm_cd = c.itm_cd And b.sku_num = d.sku_num" & _
" and c.itm_cd = '" & txtItemCode.Text & "' group by a.sku_num, b.size_cd, b.color_des, b.first_rcv_dt, d.upc_cd" & _
" order by a.sku_num"
Case "bmnStore"
.Clear
.Rows = 2
.Cols = 6
.FormatString = "^Item code |^QTY |^Store Code |^District Code |^Store Name |^Square Footage "
strsql = "select a.itm_cd, sum(c.avail_qty) qty, c.store_cd, d.op_dist_cd, d.store_name, " & _
" d.sq_ft from gm_itm a, gm_sku b, gm_inv_loc c, store d" & _
" Where a.itm_cd = b.itm_cd And b.sku_num = c.sku_num and c.store_cd = d.store_cd" & _
" and a.itm_cd = '" & txtItemCode.Text & "'" & _
" group by a.itm_cd, c.store_cd, d.op_dist_cd, d.store_name, d.sq_ft"
Case "bmnSKU"
.Clear
.Rows = 2
.Cols = 8
.FormatString = "^SKU |^QTY |^Size |^Color |^Store Code |^Store Name |^District Code |^Square Footage "
strsql = "select a.sku_num, sum(a.avail_qty) qty, b.size_cd, b.color_des, a.store_cd, d.store_name, d.op_dist_cd, d.sq_ft" & _
" from gm_inv_loc a, gm_sku b, gm_itm c, store d" & _
" Where a.sku_num = b.sku_num And b.itm_cd = c.itm_cd And a.store_cd = d.store_cd" & _
" and c.itm_cd = '" & txtItemCode.Text & "' group by a.sku_num, b.size_cd, b.color_des, a.store_cd," & _
" d.store_name , d.op_dist_cd, d.sq_ft order by a.store_cd, a.sku_num"
End Select

Set rsmain = New ADODB.Recordset
rsmain.Open strsql, cn, adOpenKeyset, adLockReadOnly
If rsmain.EOF Then
MsgBox "This item does not have any current inventory information.", vbCritical, "Error"
'txtSOH.Text = ""
Exit Sub
Else
Do While Not rsmain.EOF()
If MSFItem.TextMatrix(1, 0) = "" Then
inti = 1
Else
inti = MSFItem.Rows
MSFItem.Rows = MSFItem.Rows + 1
End If
wasNull = False
Select Case Button.Key
Case "bmnSize"
.TextMatrix(inti, 0) = rsmain("sku_num")
.TextMatrix(inti, 1) = rsmain("qty")
.TextMatrix(inti, 2) = IfNull(rsmain("size_cd"), wasNull, "")
.TextMatrix(inti, 3) = IfNull(rsmain("color_des"), wasNull, "")
.TextMatrix(inti, 4) = IfNull(rsmain("first_rcv_dt"), wasNull, "")
.TextMatrix(inti, 5) = IfNull(rsmain("upc_cd"), wasNull, "")
Case "bmnStore"
.TextMatrix(inti, 0) = rsmain("itm_cd")
.TextMatrix(inti, 1) = IfNull(rsmain("qty"), wasNull, "")
.TextMatrix(inti, 2) = IfNull(rsmain("store_cd"), wasNull, "")
.TextMatrix(inti, 3) = IfNull(rsmain("op_dist_cd"), wasNull, "")
.TextMatrix(inti, 4) = IfNull(rsmain("store_name"), wasNull, "")
.TextMatrix(inti, 5) = IfNull(rsmain("sq_ft"), wasNull, "")
Case "bmnSKU"
.TextMatrix(inti, 0) = rsmain("sku_num")
.TextMatrix(inti, 1) = rsmain("qty")
.TextMatrix(inti, 2) = IfNull(rsmain("size_cd"), wasNull, "")
.TextMatrix(inti, 3) = IfNull(rsmain("color_des"), wasNull, "")
.TextMatrix(inti, 4) = IfNull(rsmain("store_cd"), wasNull, "")
.TextMatrix(inti, 5) = IfNull(rsmain("store_name"), wasNull, "")
.TextMatrix(inti, 6) = IfNull(rsmain("op_dist_cd"), wasNull, "")
.TextMatrix(inti, 7) = IfNull(rsmain("sq_ft"), wasNull, "")
End Select
For i = 1 To .Rows - 1 Step 2
.Row = i
For j = 0 To .Cols - 1
.Col = j
.CellBackColor = &HC0FFFF
Next j
Next i
rsmain.MoveNext
Loop
End If
End With
errhandler:
If Err Then
MsgBox "Errors occured while retreiving the item information" & vbCrLf & "Please Click on Reset Button and Redo the process" & vbCrLf & Err.Number & ":" & Err.Description, vbCritical, "Error"
End If
End Sub

Private Sub MSFItem_Click()



' See if the user clicked row 0.
If MSFItem.MouseRow > 0 Then Exit Sub

' See if this is the same column.
If MSFItem.MouseCol = m_SortColumn Then
' This is the current sort column.
' Change the sort order and the column title.
m_SortAscending = Not m_SortAscending
If m_SortAscending Then
MSFItem.TextMatrix(0, m_SortColumn) = _
"> " & Mid$(MSFItem.TextMatrix(0, m_SortColumn), 3)
Else
MSFItem.TextMatrix(0, m_SortColumn) = _
"< " & Mid$(MSFItem.TextMatrix(0, m_SortColumn), 3)
End If
Else
' This is a new sort column.
' Restore the previous sorting column's name.
If m_SortColumn >= 0 Then
MSFItem.TextMatrix(0, m_SortColumn) = _
Mid$(MSFItem.TextMatrix(0, m_SortColumn), 3)
End If

' Save the new sort column.
m_SortColumn = MSFItem.MouseCol

' Sort using the new column.
m_SortAscending = True
MSFItem.TextMatrix(0, m_SortColumn) = _
"> " & MSFItem.TextMatrix(0, m_SortColumn)
End If

MSFItem.Row = 1
MSFItem.RowSel = MSFItem.Rows - 1
MSFItem.Col = m_SortColumn

If m_SortAscending Then
Select Case m_SortColumn
Case 2, 5, 6
MSFItem.Sort = flexSortNumericAscending
Case Else
MSFItem.Sort = flexSortStringAscending
End Select
Else
Select Case m_SortColumn
Case 2, 5, 6
MSFItem.Sort = flexSortNumericDescending
Case Else
MSFItem.Sort = flexSortStringDescending
End Select
End If
End Sub

Sorting Data Using DBGrid's Column Headers
Hi.

I have a form displaying table data in a DBGrid through a Data Control. Initially, I have my data sorted by some fields when displayed in the grid. Is it possible during run-time to sort the data by some other fields by clicking on the grid's column headers?

Thanks for the info in advance!

MSflex Sorting By Clicking The Column Header?
Is there a way to do so? I do not want to loop thru it, if its impossible that stinks

Sorting A Msflexgrid Based On Clicking A Column Header
hi everybody

any one knows Sorting a msflexgrid based on clicking a column header (vb 6).
please send the code..
plz reply me

thanx & bye
Jafer
jaferali2001@yahoo.com




 

Listview Column Headers.
Hello All,

I'm haveing a problem with my listview object.

I onl need to have 5 columns shown on the list. However, no matter what I do there is always 6.

Anyway of changing this. I went to column headers & there is only 5 listed. Why do I keep getting six columns?

Thx
Kao.

Listview: Fix Column Headers
Hallo!
How can I prevent the user resizing my listview columns?

Another question:
Can I set the style of a button, so that I get the look of: pushed in, when it is clicked on?

Thank you

Listview Column Headers
Hi-
I am facing problem in Data alignment(right alingment) when I am adding icon in my Listview column headers. Can anybody tell me how can I fix data as right alingment if I use icon in Listview column header?

Sohel

Column Headers In Listview
Hi-
I am trying to wrapping the column header text in two lines but I couldn't. Can anybody tell me how can I wrap/show column headers full text in two lines?

Sohel

How To Get Up Down Arrows On ListView Column Headers
By up down arrows I mean the little arrows that appear in the column headers to indicate whether the data is sorted by ascending or descending order. Anyone know how to have these appear?

Removing Column Headers In Listview
Hello all

I need some help with this,
I have found useful posts on this forum but couldn't find what I am looking for so if you know a post please guide me,
here is the problem:
I have a listview box that loads entries into the box a text file using the code below that I got from a post in the forum,

PHP Code:



Public Function load_listview(MyList As ListView, MyFile As String) 
    Dim line As String
    Dim mydata
    Dim row
    
    MyList.ListItems.Clear
    MyList.View = lvwReport
    
    Open MyFile For Input As #1
    mydata = Split(Input(LOF(1), 1), vbCrLf)
    Close #1
    'mydata = Split(line, ",")
    row = Split(mydata(0), ",")
    
    x = MyList.ColumnHeaders.Add(, , row(0))
    x = MyList.ColumnHeaders.Add(, , row(1))
    x = MyList.ColumnHeaders.Add(, , row(2))
    x = MyList.ColumnHeaders.Add(, , row(3))
    
    For i = 1 To UBound(mydata)
      row = Split(mydata(i), ",")
      
       x = MyList.ListItems.Add(, , row(0)).ListSubItems.Add(, , row(1))
       x = MyList.ListItems(i).ListSubItems.Add(, , row(2))
       x = MyList.ListItems(i).ListSubItems.Add(, , row(3))
    Next i
    
 End Function 





all works well, but it seems to load the column headers twice, I am not sure why, in my text file I have the column header titles only listed once!

I want to remove the duplication in the listview for the column headers,
How do I do that?
I know that

ListView1.ListItems.Clear

Will clear the items in the listview but how do I clear the column headers?

Thanks for reading

Adjust Column Headers Ina A Listview
Hi people
how can I do to lock the columns header of a listview, to don't allow the user change the width of each column

Height Of Column Headers In A Listview
How do I control the height of a listview columnheader? This is my initializing code, and below is what comes out of it,
Code:
code, and the attached picture shows what it produces.
Private Sub InitListView2()
Dim lvw As Single

lvw = ListView2.Width
ListView2.ListItems.Clear

With ListView2.ColumnHeaders
.Clear
.Add , "Name", "Name", lvw * 0.48
.Item("Name").Tag = LVTypeString
.Add , "Address", "Address", lvw * 0.48
End With

End Sub

Listview - Lock Column Headers?
I have a listview in report view, how do you stop the moving of column width? So they are the size i set?

2-line Listview Column Headers?
I have some very long column names with very short data & would love to be able to have 2-line headers. Can this be done? (v4). Thanks.

ListView - Information && Column Headers
Hey,



I Have a listView control with two headers. ID and Name. But i want to add the information e.g

listview1.listitems.add , , ID(1) & Name("Test")



Pleaase could someone help


Regards,
Daniel

 

Edited by - danielgraham on 4/12/2005 12:08:21 PM

Moving ListView Column Headers
Is there a way that the user can move the Column headers of a list view control. Additionally a way to select the whole line rather than the first column.

Thanks.

Drag And Drop Column Headers Listview
Hi,

How can I drag and drop column headers (and all the sub items) so that the user can reorder there view?

Many thanks

Ed

Word Wrap The Column Headers Name In Listview
Hi. I'm wondering if it is possible to word wrap the column headers so that the whole name of the column header will be seen and no ellipses will be seen to indicate that the column name is actually longer than what was shown....

I mean I have a columnheader that has a caption that requires a bigger width size. But I can only alot it to some some measurement because of the design. Can I Have it appear this way


---------------------
/ Last /
/Transaction /
---------------------


Instead of...

-----------------
/ Last Trans.../
----------------

Anyone has an idea?

Listview, Sorting/right Clicking Trouble
I've include some reworked base code that shows the problem that I'm having and fortunately once I have changed a few things around I'm still getting the same results.

When you run the program you will find that when you right click on the listview everything seems to be fine and it pops up the pop up menu just like it should. In the 5th and 6th columns it also shows you what entry you clicked on by number and by the persons name.

When you go and sort the list it isn't working properly. Only by running can you get an idea of what is going on.

Where am I screwing up? Most everything I have in their so far has been cut and paste with only a few minor variations for the program specifics that I'm dealing with.

Thanks.

ListView's Column Headers Text Color (URGENT!!)
Hi,
I need to find out a way to change the fore color of the text in the column header of a list view. So, if anyone knows anything about it, or has the code to do the same, please hit me back soon as this is really urgent.
Thanks a lot in advance.
Bye

Right Clicking On Listview Column
I have seen it be done in .Net but not in plain VB.
Anyone know how to get events on right clicking on the columns in a listview?

Find Listview Subitem's Index By Clicking On The Column
Just wanna know if we can track or select a listview subitem's index by clicking the corresponding subitem in the list view

ex:

Name Age Sex Place

Andy 12 m LA
Brad 32 m NY
Kein 12 m TX
Andy 12 m TX

Suppose i clic on the second row , 3rd subitem = "NY", it should written the subitem index as 3.

Replies appreciated,
Thnx.

Listview Column Sorting
I am using the following to sort my listview colums ascending and descending, but there is a small problem:


Code:
Private Sub lstCustomer_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
ColumnSort lstCustomer, ColumnHeader
End Sub
Public Sub ColumnSort(ListViewControl As ListView, Column As ColumnHeader)
With ListViewControl
If .SortKey <> Column.Index - 1 Then
.SortKey = Column.Index - 1
.SortOrder = lvwAscending
Else
If .SortOrder = lvwAscending Then
.SortOrder = lvwDescending
Else
.SortOrder = lvwAscending
End If
End If
.Sorted = -1
End With
End Sub
All the rows sort correctly except a row with a unique id number. this row contains:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ,13 ,14 ,15 ,16 ,17 ,18 ,19 ,20 ,21, 22
but i sorts it like so:
1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 21, 22, 3, 4, 5, 6, 7, 8, 9.
any ideas why???

Column Sorting In ListView
ello.

i'm using a ListView control and i've pretty much got it sussed apart from the sorting bit. i've got the sorting working no problem, but in a lot of programs the sort buttons (columnHeaders) have these little embedded arrows on them indicating which way the column is sorted in...

how do i do that??

Sorting A ListView Column Numerically
Hello All,

I'm using a list box (for the first time) to store some info for the user. The first column is an ID field from a database table, so I would like it to be numeric. However, when I create the ListItems using .ListItems.Add it stores the values as text. Because of this the sort order is all screwed up (ie 10 comes before 2).

I guess my question is "Is there a way to change this so I can sort these values numerically?"

Thanks for any help you can lend,
illsorted

**RESOLVED***Sorting ListView Column
Hey everyone
I have two columnar listview.
1st Column: Name
2nd Column: Date

I wish to sort the listview by Date Column, is it possible?

Thanks!

ListView Column Sorting [*Resolved*]'
How do i sort a specific column in a list view either asc or desc

Thanks in advance

Problem With Listview Column Sorting
Hello!

I'm trying to sort the data in a Listview that contains the list of Files/Folders along with their sizes in sub-item. I want to sort the listview content based on Size. However, I found that Listview control does not recognize the numeric data as Numbers and it treats it as Strings while attempting to sort. I found that number 9.1 is shown above 81! This is not a correct sorting, right? Is there any solution for this?

To make my query clear, I have created a small Demo program. Please see the code, run the program and you will realize what I'm talking about. Is there any solution for this? I'm not finding any. Please download the Demo project from following link ...

www.orbitfiles.com/download/id470769612

Waiting for your reply ...

Regards,

Ruturaj.

Sorting ListView In Report Mode...(more Than One Column)
Hi,
I was looking for a way to sort the content of the items that I have in a listview...

let's say something like:

Code:
Product Exp. Date Price

Bread 08/23/2002 0.25
Bread 08/28/2002 0.25
Milk 09/01/2002 1.00
Milk 09/05/2002 1.00


note that the sorting is name of the product & exp. date with the exp. date in asc as the name of the product is...

when I load the listview...I have no problem at all I just sort the recordset on the name of the product & the exp. date...and I have the ListView filled just the way I want... the problem comes when I move the products to another ListView there the products can be sorted only by one of this...name of the product or by exp. date but not by the two of them...

does anyone knows a workaround on this?
(the problem comes when i return the products from one listview to another and when moved in random order...

Thanks!

Problem With Listview Column Sorting (numbers Not Getting Sorted Properly) ...
Hello!

I'm trying to sort the data in a Listview that contains the list of Files/Folders along with their sizes in sub-item. I want to sort the listview content based on Size. However, I found that Listview control does not recognize the numeric data as Numbers and it treats it as Strings while attempting to sort. I found that number 9.1 is shown above 81! This is not a correct sorting, right? Is there any solution for this?

To make my query clear, I have created a small Demo program. Please see the code, run the program and you will realize what I'm talking about. Is there any solution for this? I'm not finding any. I have attached the code to this comment.

Waiting for your reply ...

Regards,

Ruturaj.

Problem With Listview Column Sorting (numbers Not Getting Sorted Properly) ...
Hello!

I'm trying to sort the data in a Listview that contains the list of Files/Folders along with their sizes in sub-item. I want to sort the listview content based on Size. However, I found that Listview control does not recognize the numeric data as Numbers and it treats it as Strings while attempting to sort. I found that number 9.1 is shown above 81! This is not a correct sorting, right? Is there any solution for this?

To make my query clear, I have created a small Demo program. Please see the code, run the program and you will realize what I'm talking about. Is there any solution for this? I'm not finding any. I have attached the code to this comment.

Waiting for your reply ...

Regards,

Ruturaj.

Problem With Listview Column Sorting (numbers Not Getting Sorted Properly) ...
Hello!

I'm trying to sort the data in a Listview that contains the list of Files/Folders along with their sizes in sub-item. I want to sort the listview content based on Size. However, I found that Listview control does not recognize the numeric data as Numbers and it treats it as Strings while attempting to sort. I found that number 9.1 is shown above 81! This is not a correct sorting, right? Is there any solution for this?

To make my query clear, I have created a small Demo program. Please see the code, run the program and you will realize what I'm talking about. Is there any solution for this? I'm not finding any. I have attached the code to this comment.

Waiting for your reply ...

Regards,

Ruturaj.

Get Column Headers
I read an XML into Excel, then I want to get the column headers into a string array. Check the pic for explanation

Thanks

Column Headers
I have a VB6 app that returns data from a MySQL database to an Excel sheet. I can retrieve the data to Excel, but can't seem to get the column headings from the MySQL table to the Excel sheet. Can someone help me with this? Thanks.

Column Headers
Is there anyway to disable a column headers width from being adjusted during run time.

Dazza

Column Headers
How can I change the caption on a column header on a bound datagrid control?

Thanks!

Column Headers
Please help
When I try to add column headers to my list box using
Dim clmx as ColumnHeader
I am receiving an error User defined type not defined.
If I change columnHeader to object on the add method i get method or data not found. I have check other examples of code and they are doing the same. Have i missed something in the properties box. I am using VB6. Also i am trying to add this in the Sub Form_Load()
thanks for any suggestions.
Kezza

MSHFlexGrid Column Headers
I sure hope someone can help...

I am using an MSHFlexGrid, and the second band is displayed verically. I have the second band set to display column headers. However, after I rebind the grid with new data they are no longer there. I am running this after I rebind, but it still doesn't show:

Me.grdInvoice.ColHeader(1) = flexColHeaderOn

Any thoughts?

Listbox Column Headers Name
Hi,

I have a userform in Excel VBA which is connected to Access database.
there is a listbox in that userform and through SQL query I take the data from access table and add it to the listbox.
I know how to make it multi column listbox,currently I am using columncount property as 5 so there are 5 column.

the problem is that I don't know how to name the headers.
I know to use rowsource but I only can use it when data is from excel sheet. but in my case I need to get the data from access table.
can somebody please help how to get the headers name

Thanks

Column Headers In A ComboBox
Hi.
VBA - Access

I have been working on a way to put all the headers from a Table called "Data" into a combobox. The column headers aways change so i cant just add them.

Ive been trying to write a SQL statement but i never did SQL in my studies. But i think it would be the best way to do it. So an examples on this would be great.

Thanks.

Column Headers And Icons
Windows Explorer indicates the sort column/direction by an arrow icon placed after the columnheader. Selection of any particular header does not affect the alignment of that column.
I have searched previous posts, and have learned how to show or hide the icon in a listview control, but have not been able to place the icon after the columnheader. One of my columns has alignment lvwColumnRight. When the header is selected I show the icon, (on the left, because that is the best I can do), but I am unable to prevent the column reverting to alignment left.

Column Headers In Listboxes
hi,
how can i add column headers to my listboxes, just like in windows file explorer in the "details" view, is it a standard listbox or is it a special active x control?

cao
mirza

MSFlexigrid Column Headers
Hello guys,

Hope you could help me with this one,,,how do i add column names on a msflexigrid?

Get Column Headers In Datagrid
Hi all!

I would like to ask if anyone knows how to get the names of the column
headers from a datagrid?
My grid is populated at run from an excel file. So the column names are not defined at design time.

Please help.

Column Headers In Listbox
Hello People,

I have a listbox on a form which is called by the following:


VB Code:
Call Pg1aList(reclist)


Where reclist is the name of my Listbox and Pg1aList is this function:


VB Code:
Public Function Pg1aList(lstholder As ListBox)        On Error GoTo ErrHandler    Dim pg5 As ADODB.Recordset    'Dim strText1 As String     Set pg5 = MyConn.Execute("SELECT RecID, indname, datedeveloped FROM apprecords")    lstholder.Clear  With pg5    Do Until .EOF        lstholder.AddItem (pg5("indname"))        lstholder.ItemData(lstholder.NewIndex) = pg5("RecID")        .MoveNext    LoopEnd With      Exit Function    'error handlerErrHandler:    MsgBox Err.Description        pg5.Close    Set pg5 = Nothing    End Function


This works fine, but I would like to have the two column names that I am using brought into the top of the Listbox as well. I basically want Name and Date to appear at the top of the Listbox, and then all the necessary records.

Any ideas on how I do this...??

Any help would be appreciated,

Al...

Column Headers In A MSFlexGrid
Does anyone know of a way to set up a MsFlexGrid's headers without using the FormatString Property?

ListBox Column Headers
I know how to add columns headers (Icons and text) but, how can I add data under them. I use this:


Code:
with listbox1
.listitems.add , , "This is an Item", 1, 2
.listitems.add , , "This is another Item", 1, 2
end with


to add items to my listbox. Now, these go under the first column header, how can I make the code so there is some under the second and the third column header.

Thanks!

VB Flexgrid Column Headers
How do you add column headers (text) to the flexgrid control?

Copyright © 2005-08 www.BigResource.com, All rights reserved