Solved

How can i tell which column has been clicked in a listview?

Posted on 2006-07-12
2
192 Views
Last Modified: 2010-04-23
I have an app with a ListView that is set to Details and has several columns. The ListView has a ContextMenu that I want users to be able to use to right click anywhere on the ListView and then select which way they would like the column they clicked on to be aligned. I am using the following code to align the columns:

lstvwColumns.Columns(3).TextAlign = HorizontalAlignment.Left

The problem I am having is how to get the above code to know which column to align depending on where on the ListView they user has clicked. I can find out which row but I don't know how to find out which column.
Can anyone help?
Thanks.
0
Comment
Question by:kiranboi
  • 2
2 Comments
 
LVL 8

Accepted Solution

by:
plq earned 500 total points
ID: 17089175
This is the only way as far as I know

You would have to trap the mouse position in the mousedown event, store it in form level x,y variables, and refer to those variables in the itemclick event. You can add up the lvw.Left plus all the column widths until you exceed the x value, then you know you're on the right column.

BTW A better approach might be to use a right click popup menu which allows the user to align left, center, align right ?? But you'd still need to identify the column
0
 
LVL 8

Expert Comment

by:plq
ID: 17090768
B ?
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now