ListView Control (VS2008)

J

John

Hi,

While doing a VB6 to VB.NET conversion, I found one task I could not figure it out:

when the listview is in detailed view (which is like a grid) ... we need to add a small icon (up and down arrow) on the right side of column header to indicate the current sort order of that column, similar to the gridview built-in function, how could I do that?

Thanks!
John
 
C

Colbert Zhou [MSFT]

Hello John,

Thanks for using Microsoft Newsgroup Support Service, my name is Colbert
Zhou [MSFT] and I will be working on this issue with you.

In order to display an up or down arrow right beside the ListView control
header. We need to draw it ourselves. The approach is setting OwnerDraw
property to true and register the following three events, DrawColumnHeader,
DrawItem, DrawSubItem.

The implementations of these event handles are,

Private Sub ListView1_DrawColumnHeader(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.DrawListViewColumnHeaderEventArgs) Handles
ListView1.DrawColumnHeader
e.DrawBackground()
e.DrawText()
Dim uparrowFont As New Font("Calibri", 8)
Dim uparrow As New String(New Char()
{Microsoft.VisualBasic.ChrW(&H2191)})
e.Graphics.DrawString(uparrow, uparrowFont, New
SolidBrush(Color.Black), e.Bounds.Right - 15, 1)
End Sub

Private Sub ListView1_DrawItem(ByVal sender As System.Object, ByVal e
As System.Windows.Forms.DrawListViewItemEventArgs) Handles
ListView1.DrawItem
e.DrawDefault = True
End Sub

Private Sub ListView1_DrawSubItem(ByVal sender As System.Object, ByVal
e As System.Windows.Forms.DrawListViewSubItemEventArgs) Handles
ListView1.DrawSubItem
e.DrawDefault = True
End Sub

In DrawItem and DrawSubItem, we set the e.DrawDefault to true which lets
the system to draw them. And in the DrawColumnHeader event, we call
DrawBackground and DrawText to draw the default text and background. And
then we call DrawString to draw an Unicode up arrow at the end of the
header bound.

Please let me know if this helps for your scenario. And if you have any
future questions or concerns, just let me know! I will try my best to
provide future assistances. Have a nice day!


Best regards,
Colbert Zhou (colbertz @online.microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
C

Colbert Zhou [MSFT]

Hello John,

I am writing to check the status of the issue on your side. Could you
please let me know if the suggestion works for you or not? If you have any
questions or concerns, please feel free to let me know. I will be more than
happy to be of assistance.

Have a great day!

Best regards,
Colbert Zhou ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

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

J.B. Moreno

John said:
Hi,

While doing a VB6 to VB.NET conversion, I found one task I could not figure
it out:

when the listview is in detailed view (which is like a grid) ... we need to
add a small icon (up and down arrow) on the right side of column header to
indicate the current sort order of that column, similar to the gridview
built-in function, how could I do that?

It's in C#, but check out
http://www.thebitguru.com/articles/16-How%20to%20Set%20ListView%
20Column%2520Header%2520Sort%2520Icons%2520in%2520C%23/208-Introduction
it has one of a couple of different ways to do this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top