473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Getting column header text

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
5 4890
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

"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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Shravan Kumar | last post by:
Hi, I am using my code to set column widths of datagrid columns dynamically, but when I am setting the column widths to zero, the header text of the column whose width is made to zero is...
1
by: Webgour | last post by:
Hi, I'm tring to add a column to a datagrid with a linkbutton as header that can be used to sort the column. The column and the linkbutton are added programmatically (see below). However the...
19
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to...
1
by: Gunjan Garg | last post by:
Hello All, I am working to create a generic datagrid which accepts a datasource(ListData - This is our own datatype) and depending on the calling program customizes itself for sorting,...
3
by: Hans Merkl | last post by:
Hi, I was wondering if it's possible to bind the header text of a GridView column to a method of an object I have. At the moment I am setting the header texts in Page_Load but I was wondering if...
3
by: TPhelps | last post by:
I have a sample of an unbound (autogeneratecolumns is true) sortable/pagable datagrid that works. I want to change one of the columns to a hyperlink. The examples I find use a bound column. I...
4
by: Yin99 | last post by:
I have a Gridview binding to a DataTable source. I'd like to set the column with of the second column. I cannot do this apparently because when AutoGenerateColumns=true, they do not appear in the...
1
by: Iain Wilson | last post by:
Hi all I have a simple 2 column page (see below) styled by CSS In column 1 there are a list of href's. What I want to do is to have an image displayed in column 2 in response to a href...
0
by: bharathreddy | last post by:
Hi All, I am using a listview control in my usercontrol so that it can be used in more than one form. This user control has one column extraw, so i want to make it invisible depending on the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.