Solved

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

Posted on 2006-07-12
2
194 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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

803 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