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




Sorting Listview (2 Columns)


Hi !

Is it possible to sort a listview by 2 columns ???

I want that my app sort the 1st Columns and sort the 2nd Columns without modifying the order of the 1st column...

I try this but It does'nt work


VB Code:
ListView1.SortOrder = lvwAscending  ListView1.SortKey = 0  ListView1.SortKey = 1

Thanks in advance !




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Sorting In A ListView With Columns
I hope you guys can help me out as it's getting frustrating

The code I have so far when a column header is clicked on in the listview is this -


Code:
Private Sub lvFaults_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)

If Not lvFaults.Sorted Then
lvFaults.Sorted = True
End If

Dim intColumn

Select Case ColumnHeader
Case Is = "Fault No"
intColumn = 0
Case Is = "Reported By"
intColumn = 1
Case Is = "Office"
intColumn = 2
Case Is = "Date"
intColumn = 3
End Select

If lvFaults.SortOrder = lvwAscending Then
lvFaults.SortKey = intColumn
lvFaults.SortOrder = lvwDescending
Else
lvFaults.SortKey = intColumn
lvFaults.SortOrder = lvwAscending
End If

End Sub
This half works but the ordering is a bit funny and I'm guessing most of you know what I mean. But basically the Fault No column starts at 4 digit numbers but currently are up to 5 digit numbers (it's an autonumber from a database) so it's sorting them like this -

10282
10283
10285
8728
9644
9672

And the date is sorted like -

01/03/2004
01/10/2003
05/03/2004
09/02/2004
12/02/2004

Anyone have any ideas? Thanks

Sorting Listview Columns
I have this code to sort the columns in a listview.

Columns 1, 3, 4, 5 are not to be used for sorting.

Column 0 is a date column, so I reload the listview (from Access database) with the sort order in the SQL statement.

Column 2 is a straight forward Ascending or Descending.

The problem I am getting is that if I sort by column 2 first and then by column 0, it doesn't sort in the correct date order, even though the strSQL statement is correct.

Any ideas where I am wrong?

I am guessing it's something to do with how I set the Listvew.SortKey maybe!


Code:
Select Case ColumnHeader.Index - 1
Case 0
If lvwCourseListYear.SortKey <> ColumnHeader.Index - 1 Then
lvwCourseListYear.SortKey = ColumnHeader.Index - 1
End If

'\store the sort order
If strCourseSortOrder = "Descending" Then
strCourseSortOrder = "Ascending"
Else
strCourseSortOrder = "Descending"
End If

strSQL = "SELECT * FROM tbl_CourseList"
strSQL = strSQL & " WHERE Course_Year = '" & cmbYear(1).Text & "'"

Select Case strCourseSortOrder
Case "Ascending"
strSQL = strSQL & " ORDER BY Course_Date"
Case "Descending"
strSQL = strSQL & " ORDER BY Course_Date Desc"
End Select

lvwCourseListYear.ListItems.Clear

rs.Open strSQL, cn, adOpenForwardOnly, adLockPessimistic, adCmdText

Do While Not rs.EOF
'add to listview
Set lvwItem = lvwCourseListYear.ListItems.Add(, , Format(rs.Fields("Course_Date").Value & "", "dd - mmm - yyyy"))
lvwItem.SubItems(1) = rs.Fields("Course_Day").Value & ""
lvwItem.SubItems(2) = rs.Fields("Course_Type").Value & ""
lvwItem.SubItems(3) = rs.Fields("Course_Venue").Value & ""
lvwItem.SubItems(4) = rs.Fields("Course_Times").Value & ""
lvwItem.SubItems(5) = rs.Fields("Course_ID").Value & ""
lvwItem.SubItems(6) = rs.Fields("Course_Checked").Value & ""
ctr = ctr + 1
rs.MoveNext
Loop

rs.Close

lvwCourseListYear.Sorted = True

Case 2
'Check if the Sortkey is the same a the current one
If lvwCourseListYear.SortKey <> ColumnHeader.Index - 1 Then
lvwCourseListYear.SortKey = ColumnHeader.Index - 1
lvwCourseListYear.SortOrder = lvwAscending
Else
'If the column is already selected then change the
'sortorder to be the opposite of what is currently used

lvwCourseListYear.SortOrder = IIf(lvwCourseListYear.SortOrder = lvwAscending, _
lvwDescending, lvwAscending)
End If

lvwCourseListYear.Sorted = True

Case 1, 3, 4, 5
Set rs = Nothing
Exit Sub
End Select

Sorting Listview Through Columns ???
ok i open a text file that is spilt up like so ...

MyItem.Text & Chr(9) & MyItem.SubItems(1) & Chr(9) & MyItem.SubItems(2) ' & " " & MyItem.SubItems(3)

Now i open it in the listview and it reads it fine, that is if i don't have the sorting checked off. if i have it to sort its missing some data on the second and thrid colums

I want to be able to sort the listview by clicking on the colums i searched the forums and got this but... its still giving me the same problem... missing data

here's the code I've got...

Private Sub SingersListView_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
If SingersListView.SortOrder = lvwAscending Then
SingersListView.SortOrder = lvwDescending
Else
SingersListView.SortOrder = lvwAscending
End If
SingersListView.SortKey = ColumnHeader.Index - 1
End Sub

can anyone wite the code for this that would show all my data. i'm using vb 6 with windows common controls 6(sp6). thank you

Sorting ListView Columns
Numeric values in the ListView column are sorting ASCII.
How do I sort numerically when I click the column?

Sorting Columns From Listview
Hi
, Urgent
Please, how I sorting the listview in the columns ?

eg: I have

hour_ini hou_fim room
18:20 18:50 1
18:50 19:20 1
07:00 07:30 2
07:30 08:00 2
06:00 06:30 3
Is sorted for room , I want sort for hour_ini, How do I ?
07:00

Sorting Listview By Multiple Columns
Is it possible for a listview to sort by multiple columns?

I.e Click column A then B and the listview will sort primarily by column B and any duplicated results will be sorted by column A?

E.g.

Code:
'From this,
ColA ColB
1 C
3 B
2 B
4 A
' User clicks ColA then ColB
' Would get sorted as

ColA ColB
4 A
2 B
3 B
1 C

At the moment it seems to just sort by the most recently clicked column with no clear previous order (if it should already do this then maybe to do with the custom ordering functions i'm using)

Cheers

Sorting A Listview W/ Multiple Columns..
I have two columns in my listview, and I want to sort by either column.

If I clicked on the first column, it would sort alphabetically by the first column, and same for the second.

Any help? I'm confused

Sorting Array With 5 Columns By Any Column Or Columns
Hi all!
I have an array with 5 columns:
- city
- first name
- last name
- birth date
- children quantity

How can I sort this array by any column, for example by 4?
And how can I sort it by few columns, for example:
sort by 5 then sort by 1 then sort by 3?

Resizing Columns In One Listview To Automatically Resize Corresponding Columns In Another.
I'm currently building the front end to a VB6 application. This app is largely based on entering data into a Listview. In order facilitate data entry, I need to create an editable row beneath the listview, comprising of text boxes(unless there is a better method) and an "add" button. The problem is that when a column in the Listview is moved or resized, the array of textboxes need to reflect this change of order/size, as each textbox needs to appear beneath its corresponding column. Also, if the listview contains a large number of columns, and therefore a horizontal scrollbar, the textboxes will need to scroll also... I would be very grateful for any help..! Thanks...

Sorting On 5 Columns
How do I sort on 5 different columns of data using VB?

I'm trying to sort a table using 5 different sort keys. This is what I've got so far but I'm getting the error message "Run time error 1004. Application defined or object defined error."

Code:
Selection.Sort _
Key1:=Range("I2"), Order1:=xlAscending, _
Key2:=Range("L2"), Order2:=xlAscending, _
Key3:=Range("J2"), Order3:=xlAscending, _
Key4:=Range("K2"), Order4:=xlAscending, _
Key5:=Range("B2"), Order5:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

I'm assuming that I can't use more than the 3 keys that Excel gives you by default, so my code is incorrect. Either that or I hosed up my code.

Sorting Columns
I'm having difficulty sorting columns correctly in Excel. Since I'm kind of a hack, I usually record macros of the actions that I can do from drop-down menus and then adjust them to my needs. Recording the macro doesn't seem to help in this case; here's why:

I have data that are numbered, say, 1-50 descending down a column. If I use the sort command to sort them, I end up with this:

1
10
11
12
13
14
15
16
17
18
19
2
20
etc...

Any ideas why it does this and how to correct it?

Thanks!

Sorting Columns
Hey all i am in need of some help trying to sort a column in my sheet. This is the code i have that works....

Code:
Dim theNextLine As String

theNextLine = Right("Data!B2:" & Range("B2").End(xlDown).Address, 1)
Worksheets("Data").Range("B2:B" & theNextLine).Sort Worksheets("Data").Range("B2")
BUT it only sorts the B column and doesnt move any of the other information in the other colums with it!

How can i do this to achive what you would get with highlighting the "B" column and hitting the filter button and telling it to sort A-Z?

BTW, the reason why i want to sort by the "B" column is that its the last name of the people...

Thanks!
David

Sorting On More Then 3 Columns ?
When i record the sorting of my range on 3 columns, this is the code i end up with :


Code:
Sub Macro1()
Range("A10").Select
Range("A10:R111").Sort Key1:=Range("C11"), Order1:=xlAscending, Key2:= _
Range("E11"), Order2:=xlAscending, Key3:=Range("G11"), Order3:= _
xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:= _
xlSortNormal, DataOption3:=xlSortNormal
End Sub
As i need to sort on more then 3 columns, i simply tried to add another key (key4), like this :


Code:
Sub Macro2()
Range("A10").Select
Range("A10:R111").Sort Key1:=Range("C11"), Order1:=xlAscending, Key2:= _
Range("E11"), Order2:=xlAscending, Key3:=Range("G11"), Order3:= _
xlAscending, Key4:=Range("Q11"), Order4:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:= _
xlSortNormal, DataOption3:=xlSortNormal, DataOption4:=xlSortNormal
End Sub
It doesn't work, apparently Excel doesn't like my fourth key

Does anyone know how to sort on 4 (or more) columns ?

Sorting Columns In LV
VB Code:
Private Sub srvplayers_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)        'Check if the Sortkey is the same a the current one    If SrvPlayers.SortKey <> ColumnHeader.Index - 1 Then        'When a column is clicked set the sortkey        'to the columnheader index -1        SrvPlayers.SortKey = ColumnHeader.Index - 1        SrvPlayers.SortOrder = lvwAscending    Else        'If the column is already selected then change the        'sortorder to be the opposite of what is currently        'being used        SrvPlayers.SortOrder = IIf(SrvPlayers.SortOrder = lvwAscending, _                                lvwDescending, lvwAscending)    End If        'Set the sorted property to use the new sortkey    'and sort the contents    SrvPlayers.Sorted = True    SrvPlayers.Sorted = FalseEnd Sub


Now, that normally works okay. But i have added in the first row numbers from one to about 30. This code sorts them crazy, it has 9 and 10 as the first two!Are they being stored as variants or strings?

Adding Columns To A Listview That Already Has Columns
Hi

I'm new to VB6 (I usually program in VB.NET but have been asked to make an enhancement to a VB6 application).

I have a listview which has columns defined within it in the designer. The code I am looking at then retrieves data from a db and puts it into the listview.

I've been asked to add another column in the middle of the listview e.g. there are 10 columns defined in the designer and this new column needs to go at position 6. However, the data that needs to go in the new column needs to come from a different query than the one that fills the other columns. I therefore thought that the best way to do it was fill up the original columns and then slot in the new column and fill it from another query. I've been searching around but can't find any example of how to do this.

Please can anyone help, or suggest a better way to do it? Thanks!

Sorting Array With 2 Columns
Hello, in my game I have the high scores. They are stored as the Players name and then the score, like;
Kevin,2548
Peter,36982

When someone ends the game, I would like loop through the ini file used to store the high scores and read them into an array or listbox, the latter so I can make sure its working).

So i would have the first 10 fields filled with the data and then i will make the 11th the new entry. I would like to sort them by the score and then name and then write the first 10 back into the file, dropping the 11th since it would then be the last one.

using either an array or a listbox would be fine.

MSFlexgrid - Sorting Columns On The Fly
I have an existing MSFlexgrid control that displays data.

Is there a way to click on top of a column and have the column sort the data?

Click once and have it in ascending order. Click again and have it descending order.

Any code or clues would be appreciated.

Sorting MSFlexGrid On Two Columns
Hi all,

How to sort a flexgrid on two columns.

Sorting Columns In Grid
<html><div style='background-color:'><DIV></DIV>
<P>Hi Friends,</P>
<P>I would like to sort on any one of the columns simply by clicking on the column header in Sheridian DB Grid.</P>
<P>Can anyone please let me know,</P>
<P>Thanks,</P>
<P>VKT<BR><BR><BR><BR><BR><BR></P>
<DIV></DIV></div><br clear=all><hr>Talk to Karthikeyan. Watch his stunning feats. <a href="http://g.msn.com/8HMBENIN/2731??PS=">Download images.</a> </html>

Sorting By Two Columns In A Flexgrid
Greets,

I know how to sort a flexgrid by one column using the flexSortGenericAscending/Descending method, but if I have a grid that has two columns, say "Name" and "City" and I sort by the "Name", then the city is out of order, and if I then sort by "City" then names are then out of order. Is there some way to sort this so that when I sort by "City", all the names for that city are also in order?

If I'm not being clear, let me know. I'll try to explain it better.

Sorting Two Or More Columns With A DBGrid
Hello,

Is it possible to sort multiple columns at the same time with a DBGrid HeadClick event? The HeadClick event with a DBGrid takes only one parameter. I would like to use the HeadClick event rather than using a SQL text such as

SELECT * FROM Clean ORDER BY OPER_NBR, TASK_NBR ASC

to sort the data.
If it were possible, any help would be much appreciated.

Thanks

Karl

Sorting Columns In Grid
Is there a grid that you can transfer columns from one place to another during run time and sort columns from ascendint to descending also during run time?

Sorting Columns In An Excel Spreadsheet
Hello everybody,

I am having some trouble sorting excel spreadsheet columns from a VB application and was hoping somebody could help...

Here is what I am doing:

dim xlApp as Excel.Application
dim xlBook as Excel.Workbook
xlBook.Worksheets(1).Range("A1:C14").Select


and so i want to sort ascending on column C (with all the data in columns A and B still matching the data in C, hence the select of the whole thing), and the command that the macro recorder gave me was:

xlApp.Selection.Sort Key1:=Range("C1"), Order1:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

which I know may not be the same thing I need because it is VBA, not VB. I have tried a couple of different things (such as using "Cells" and specifying the entire range), but keep getting this error:

Run-time error '1004':

Method 'Range' of object '_Global' failed



Can anyone help me out and let me know what I am doing wrong, or shoot me a sort command that works in VB?

Thanx a bunch in advance!

ralph m.

Excel VBA Help - Sorting All Columns Independantly
I have an Excel sheet, 4000rows, 100 columns, and I can't figure out how to write a clean macro that will sort all columns independently. Data in each column is not at all related to data in other columns. Fyi, I do have headers in the first row. Thank you very much. If I wasn't clear, please feel free to ask questions. Dan

Sorting Auto-filtered Columns
One of my first VBA projects required the ability to sort columns that had auto-filters already applied. Since I couldn't find any examples at the time, I rolled my own:
http://www.mrexcel.com/forum/showthread.php?t=50966
Sorry about my lack of knowledge of code tags at that time, and that I didn't make it more generic or comment it. To be honest, sharing and discussing code with others was a foreign concept to me at the time.

It seems to me this should be a common thing that one might want to do. Strangely, I thought I had originally posted the code on this site, but I see I was wrong. If anyone has seen this done before, or has other ideas, let me know. If it is unique, by some stroke, I would be happy to clean it up and place it here.

FlexGrid Sorting/Rearranging Columns
I think I finally figured out how to use the FlexGrid control. I have been told that you canít sort by column in a FlexGrid, but there is a .Sort property. I was wondering how to use that property. I saw the constants in the Object Browser, but how do I apply the property to a certain column? Or can it only be applied to the left most column? In the Object Broswer it says is sorts selected rows, does that mean I canít sort the entire grid by column?

Which brings me to my next question: how do I rearrange columns? Like if someone drags a column heading to the other side of the grid I want it to drop there and all the text in that column to move with it. Would I have to manually write all the code including rewriting the whole text matrix?

Also, how do I get the text in the upper cell of a FlexGrid to be left aligned?

Sorting Columns In Msflexgrid (RESOLVED)
Hi there...

I'm trying using an MSflexgrid and I would like the grid to automaticly sort the columns once I clic the header...

Do you guys have any good code for that?..

Thanks in advance

Help On Sorting Listbox (Columns Spacing Etc)
Ok thanks you to the people who answered my previous thread on adding an item from one list box to another. However I now need help on organising this data so that it is nicely presented. As explained in my original thread I had an extremely long sentence of stored code which was placed inside a random access file (this sotred the users details such as there address, postcode etc).

However now that I that I can add a single record from the main list box (Lst_Users) to the second list box (Lst_Details) I want this data to become organised (in the second list box). Is there a way of restricting a certain amount of characters per line in a list box. This way I could forcefully seperate the long line of code in the list box. Any other ideas of seperating this long string would be welcome, thanks in advance.

Sorting Columns In Excel Using Code
Hi..need some serious help with excel...


if i have 3 columns with info in it. I wan to create a drop down menu with the terms "ascending" and "descending" to sort> i believe visual basic and help me. If it is true, please advise. Thanks. Wheneever i choose ascending, it should sort without me havign to go and manually sorting it using the AZ buttons!!.. THanks. i need this for ease of use.

Sorting Columns In Sheridian DBGrid
I would like to sort on any one of the columns simply by clicking on the column header in Sheridian DB Grid.

Can anyone please let me know,

Thanks,

VKT

Sorting Columns In Sheridian DBGrid
Hi friends,

I would like to sort on any one of the columns simply by clicking on the column header in Sheridian DB Grid.

Can anyone please let me know,

Thanks,

VKT

Sorting On Columns When Header Clicked: MSHFlexGrid
Can someone please help? I have an MSHFlexGrid and want to be able to click each header and sort by that column, either ASC or DESC. I would like to get away without having an extra button if it's possible.

I can do it with a Datagrid using the headclick event and what I do is, when they first click the column, sort it ASCending and place (A) in front of the column header. If/when they click that header again, if there is (A) in the header, then sort it DESCending and put (D) in place of the (A). This works really well with the datagrid, but I don't know how to do it for the MSHFlexGrid.......

VBA Code For Excel: Sorting By Multiple Columns At Once
Hi,

I am having trouble finding examples of code to where I can sort an excel spreadshet by multiple columns at one time.

The code I'm using for sorting one at a time is as follows:

excelApp.Worksheets("Temp").UsedRange.Sort excelApp.Range("A1"),xlAscending

What do I have to add to this to sort by column b as well?

An example of what I'm trying to do...Say there are 50 people divided in to 5 teams. Column A is their team Number and Column B is their last name. I want to sort them first by their Team Number then Second by their last name. This is really easy to do in excel using their sort tool, but I am generating a ton of reports through this code and it would be a pain to have to do this manually for each report.

Thanks for any help you can provide in advance.

DL

Sorting On DATE Columns In MS List View
Does anybody know how to get this to work?

The listview seems only capable of accepting strings as it's items so dates have to be converted to text and therefore are sorted as text.

How can I get around this?

ListView Columns
How do i add columns to a ListView and also how do i insert information into a listview box? For my listview i require 3 columns: 'Artist', 'Track' and 'CD'.

I have tried adding columns using the properties dialog, but they don't appear when i run the form.

Any help is much appreciated!

James

Listview Columns
if I do lvwListView.listitems.additem ,, "test"
it adds an item in the first column of the listview
how do i add data in the second column of a listview

ListView Columns
I have four columns in a list view, each taking up 25% of the available space. When the form resizes, I am successfully resizing the ListView, but how do I resize each of the columns back to 25% of the new size.

I have tried ListView1.ColumnHeaders.Items(0).Width, but that results in a Out of Bounds Error. I have also tried with Items(1) with the same result.

Any idaes

Listview Columns
thought i would have a go using a listview in report mode.

i must be missing something and see what.
when i insert a column and give it a caption it will insert it but then i have 2 columns.
i wanted 3 columns altogether but it shows 4, always 1 more.

what am i missing ?

thanks
thingimijig.

ListView Columns
If I have 2 columns in a ListView (set to Report), how can I add data to them? I have tried for ages, and I cant figure it out.

Columns To A ListView
Is it possible to add Columns to a ListView manually or does it have to be done at runtime?

Two Columns In Listview
sorry, this may be a silly question but its very frustrating,

all i need is for my listview to display two columns of data, taken from a query currently i can achieve one column but i need to add another with "LastName" cheers, here is my code so far


Code:
Set cn = New ADODB.Connection 'we've declared it as a ADODB connection lets set it.
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source= c:vdmcertymate VBdatadata.mdb" 'this is the connection string explained in the notes section.
cn.Open
Set rs = New ADODB.Recordset 'as we did with the connection
rs.Open "qryEmployees", cn, adOpenKeyset, adLockPessimistic, adCmdTable 'opening the recordset explained in the notes

'Code to populate the listView
While Not rs.EOF
lstvEmployees.ListItems.Add , , rs.Fields("FirstName").Value
rs.MoveNext
Wend

rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing

Me.MousePointer = 0 'Resets Mouse Pointer


oh. and how do i get the listview to add a verticle scrollbar?

Listview Columns
this is a quick question really can u parse a site out into a listview with columns for different info from the site?
its a bit tricky to explain and show you as i want to connect to a site in inet grab the source parse out some hardware information,how many on the site, and how many on order and the price into one listview nicely 'ordered with column headers..
i can connect and parse the hardware info into the listview fine but i was wondering on how to do the other parts but because u need an account on the site i cant show u it however here is some of the info from the source (the parts ive gotten out and im needing to parse out..

HTML Code:
>10/100MBPs NIC</a></td><td align="right">4.96&nbsp;£</td><td align="right"><div class="g">4</div></td><td align="right"><div class="b">2<

theres say part of the info from the source ive gotten the 10/100 "part" fine but i need to get the "4.96, class="g">4< amount and class="b">2< amount (which change obviously...
is this possible to parse into a listview with columns to save me having to go to the site each time and then get those parts of the info which really defeats the purpose of the program? or do i need to use a different control other than listview?
any help or tips would be great

Listview With Different Columns?
In Listview I want to create 5 columns each having column header as "S.No", "From", "Subject", "Date", "Time"
I created Column headers in design time but they are not getting displayed? Also I want that S.No column to be having Checkboxes. How to do that? Thanks.

Listview Columns
I can only select the index column out of my data when in a listview. Code and input follows: Also I cannot input files other than the one I used to test with, of the same format?! (Not the one attached)


Option Explicit

Private Sub Form_Load()
Dim K As Integer
Dim itmX As ListItem
Dim clmX As ColumnHeader

K = 1

Set clmX = ListView1.ColumnHeaders.Add(, , "Column 1", ListView1.Width / 5)


ListView1.BorderStyle = ccFixedSingle
ListView1.View = lvwReport

ListView1.ListItems.Clear

Dim FF As Integer
Dim strLine As String
FF = FreeFile
Open "C:sheet.csv" For Input As #FF
Do While Not EOF(FF)
Line Input #FF, strLine
AddListView strLine
Loop
Close #FF


End Sub

Private Sub AddListView(S As String)
Dim Ar() As String
Dim i As Integer
Ar = Split(S, ",")
If UBound(Ar) > ListView1.ColumnHeaders.Count Then
For i = ListView1.ColumnHeaders.Count To UBound(Ar)
Dim clmX As ColumnHeader
Set clmX = ListView1.ColumnHeaders.Add(, , "Column " & i + 9, ListView1.Width / 5)
Next
End If
Dim lv As ListItem
Set lv = ListView1.ListItems.Add(, , Ar(0))
For i = 1 To UBound(Ar)
lv.ListSubItems.Add , , Ar(i)
Next
End Sub

Private Sub SortListView(ByRef List As ListView, ColHeadIndex As Integer)

Dim lcv As Long 'Loop Control Variable

With List
' Make sure the Sorted property is set to true
.Sorted = True

' Sort according to the colum that was clicked (off by one)
.SortKey = ColHeadIndex - 1

' Does the column already have an icon?
If .ColumnHeaders(ColHeadIndex).Icon = 0 Then
'No, So we will assume this column is not sorted

' Set to Ascending order
.SortOrder = lvwAscending


' Set the sort order to descending
.SortOrder = lvwDescending

Else
' Otherwise sort into ascending order

' Set to Ascending order
.SortOrder = lvwAscending

End If

' Refresh the display of the ListView Control
.Refresh
End With
End Sub

Listview Columns
when using a listview in report mode, do you always have to have a blank list at the end.

when i add columns through its properties there is always another blank one, and if i try and size it to fit the size i want it either still shows a bit of the blank one or i get rid of it and a scrollbar appears.

any ideas!
thanks.

thingimijig.

ListView Columns
Sups,
I got a listview with two columns on it.
I forgot how to add item to each column.
How can I do that?
tnx.

ListView And Columns
How can I set the column width to be that of the text? I tried:


VB Code:
lstOutput.ColumnHeaders(1).Width = TextWidth(strText)


But that didn't work...

Any ideas?

ListView Columns
I have 5 columns in the ListView, all were added via code at runtime. Now, for example, I want to remove column with index 2, problem is, the data from the last column disappears and all the data gets shifted so column with index 3 will now have what column with index 2 had before removing. Is there an easy way to remove column and all the data in it (like Access 2000 does) or do I have to go item by item moving subitems from each column to previous one making 2 last columns identical in data but not column header text, then it should work, because last column will be removed anyway. Here's when another problem comes up, if I add a new column, the data from last column will become visible again, so I really didn't remove column completely, just the column header and made data in the last column invisible. Maybe when I'm adding columns, I need to specify a key or index or what not to remove it completely? I just want to remove the whole column (header and data in it) completely, and shift all the columns to the left; and when I add a new column, I want it to be "blank", meaning no data in it. Of course, it all can be done via long code. I have to set each item's subitem of the new added column to "", etc. but there should be an easier way!
Thanks

Listview Columns
I have a listview with three columns. I want to load a table of names into the listview, putting last names A-F in #1, G-S in #2, and T-Z in #3.

I know how to loop through the table and load the names, but I don't know the listview code to separate the names into columns. Any ideas?

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