By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,819 Members | 1,459 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,819 IT Pros & Developers. It's quick & easy.

Getting column header text

P: n/a
Hi to all,

i populate a ListView with data from a datareader and i just want to know
the column name of the cell that the user clicks on.

E.x., if the user clicks on the 2nd column, 3rd row in the ListView, i want
to get
the string that the column header displays.

How i can do that ?

thanks a lot for any help,

objectref
Nov 16 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi

<snip>
Hi to all,

i populate a ListView with data from a datareader and i just want to know
the column name of the cell that the user clicks on.

E.x., if the user clicks on the 2nd column, 3rd row in the ListView, i want
to get
the string that the column header displays.


"ColumnClick" event has a "Column" argument that returns
index of clicked header.

string columnCaption=listView1.Columns[e.Column].Text;

Is it what you want?

If your column captions will different from field names the
you've got to store that field names in e.g. string[].

HTH
Marcin
Nov 16 '05 #2

P: n/a

"Marcin Grzębski" <mg*******@taxussi.no.com.spam.pl> wrote in message
news:ct**********@nemesis.news.tpi.pl...
Hi

<snip>
Hi to all,

i populate a ListView with data from a datareader and i just want to know
the column name of the cell that the user clicks on.

E.x., if the user clicks on the 2nd column, 3rd row in the ListView, i
want to get
the string that the column header displays.


"ColumnClick" event has a "Column" argument that returns
index of clicked header.

string columnCaption=listView1.Columns[e.Column].Text;

Is it what you want?

Hey Marcin, thanks for the reply.

Unfortunately this is not what i want. I know this about ColumnClick event
but i need to know the column name/header
when my users click on the data cells of the listview, not on the column
header...

Do you know a way to do it ?

Thanks again,

objectref


Nov 16 '05 #3

P: n/a
I'm assuming you are talking about Details view.

I guess the problem is that there really isn't a concept of a DotNet
ListView "cell" as you describe. It's not built to act as a grid. (Note
that you cannot just look at each Column's width property and calculate
their horizontal locations because you can't tell the column ordering when
AllowColumnReorder is true.) However, the underlying Win32 ListView control
does have messages that you can use to identify the cell that was clicked.
In particular, take a look at the LVM_SUBITEMHITTEST message.

Tom Clement
Apptero, Inc.

"objectref" <ob*******@mediatrel.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...

"Marcin Grzębski" <mg*******@taxussi.no.com.spam.pl> wrote in message
news:ct**********@nemesis.news.tpi.pl...
Hi

<snip>
Hi to all,

i populate a ListView with data from a datareader and i just want to
know
the column name of the cell that the user clicks on.

E.x., if the user clicks on the 2nd column, 3rd row in the ListView, i
want to get
the string that the column header displays.


"ColumnClick" event has a "Column" argument that returns
index of clicked header.

string columnCaption=listView1.Columns[e.Column].Text;

Is it what you want?

Hey Marcin, thanks for the reply.

Unfortunately this is not what i want. I know this about ColumnClick event
but i need to know the column name/header
when my users click on the data cells of the listview, not on the column
header...

Do you know a way to do it ?

Thanks again,

objectref

Nov 16 '05 #4

P: n/a
Here's a link to some details that may help you.

http://groups-beta.google.com/group/...7?dmode=source

Tom Clement
Apptero, Inc.
"objectref" <ob*******@mediatrel.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...

"Marcin Grzębski" <mg*******@taxussi.no.com.spam.pl> wrote in message
news:ct**********@nemesis.news.tpi.pl...
Hi

<snip>
Hi to all,

i populate a ListView with data from a datareader and i just want to
know
the column name of the cell that the user clicks on.

E.x., if the user clicks on the 2nd column, 3rd row in the ListView, i
want to get
the string that the column header displays.


"ColumnClick" event has a "Column" argument that returns
index of clicked header.

string columnCaption=listView1.Columns[e.Column].Text;

Is it what you want?

Hey Marcin, thanks for the reply.

Unfortunately this is not what i want. I know this about ColumnClick event
but i need to know the column name/header
when my users click on the data cells of the listview, not on the column
header...

Do you know a way to do it ?

Thanks again,

objectref

Nov 16 '05 #5

P: n/a
Hi,
Hey Marcin, thanks for the reply.

Unfortunately this is not what i want. I know this about ColumnClick event
but i need to know the column name/header
when my users click on the data cells of the listview, not on the column
header...

Do you know a way to do it ?


I don't know a way how to do it directly.
But you can try to achive it indirectly by:

1. catch MouseDown event with GetItemAt(x, y) to find out row.
2. GetItemRect(row)
3. Iterate through column widths to find which column correspond
with e.x

Possible problem: I'm not sure about values of x(es) where horizontal
scrollbar is moved.

HTH
Marcin
Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.