Getting column header text

  • Thread starter Thread starter objectref
  • Start date Start date
O

objectref

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
 
Hi

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
 
Marcin Grzêbski said:
Hi

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
 
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 said:
Marcin Grzêbski said:
Hi

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
 
Here's a link to some details that may help you.

http://groups-beta.google.com/group...ages.csharp/msg/d4854fbb32cb2337?dmode=source

Tom Clement
Apptero, Inc.
objectref said:
Marcin Grzêbski said:
Hi

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
 
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
 
Back
Top