Sample code needed - Listview - Move columns 
Author Message
 Sample code needed - Listview - Move columns

Can someone point me to some sample code that shows the best way to allow
the user to rearrange the columns in a LISTVIEW?

--
Bill McCarthy



Sat, 05 Mar 2005 00:32:53 GMT  
 Sample code needed - Listview - Move columns
Just set the ListView control's "AllowColumnReorder" property to true; the
user can then drag and drop the columns in any order they wish.

Hope this helps!

Steven Bras, MCSD
Microsoft Developer Support/Visual Basic WebData

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? For information about the Microsoft Strategic Technology
Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.



Sat, 05 Mar 2005 01:49:12 GMT  
 Sample code needed - Listview - Move columns
Thanks for the tip.

A further question:

If the user reorders the columns in the display, does this affect the oreder
of the columns in the collection.  I have a sort routing that uses the
column index as an indicator of data type (date, string, etc.).  If they get
reordered, then my method of determining type will be off???  If so, I'll
need another method od checking this.

--
Bill McCarthy



Quote:
> Just set the ListView control's "AllowColumnReorder" property to true; the
> user can then drag and drop the columns in any order they wish.

> Hope this helps!

> Steven Bras, MCSD
> Microsoft Developer Support/Visual Basic WebData

> This posting is provided "AS IS" with no warranties, and confers no
rights.

> Are you secure? For information about the Microsoft Strategic Technology
> Protection Program and to order your FREE Security Tool Kit, please visit
> http://www.microsoft.com/security.



Sat, 05 Mar 2005 04:38:57 GMT  
 Sample code needed - Listview - Move columns
The index of the column does not change if the columns are reordered in the
ListView. You can test this by running the following code:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

        ListView1.Columns.Add("First", 50, HorizontalAlignment.Left)
        ListView1.Columns.Add("Second", 50, HorizontalAlignment.Left)
        ListView1.Columns.Add("Third", 50, HorizontalAlignment.Left)
        ListView1.View = View.Details

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
        Console.WriteLine(ListView1.Columns(0).Text)
        Console.WriteLine(ListView1.Columns(1).Text)
        Console.WriteLine(ListView1.Columns(2).Text)
    End Sub

Click Button1, and then reorder the columns; then click button2. The
console will always show:

First
Second
Third

Hope this helps.

Steven Bras, MCSD
Microsoft Developer Support/Visual Basic WebData

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? For information about the Microsoft Strategic Technology
Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.



Sat, 05 Mar 2005 05:06:45 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. How do I Move Column in ListView at RunTime

2. ListView Moving Columns

3. ListView: Does not sort on text is moved into Column 0

4. looking for sample code for moving messages

5. Sample Code Needed to Compress a MS Access file from code in a VB 6 program

6. Listview - FullRow code sample

7. Listview - FullRow code sample

8. Listview - FullRow code sample

9. ListView Sample Needed

10. Creating Listview columns via code

11. ListView: Column Text becomes Left-Aligned when ColumnHeader Icon is changed in Code

12. ListView: Column Text becomes Left-Aligned when ColumnHeader Icon is changed in Code

 

 
Powered by phpBB® Forum Software