DataGrid Column Position

bufer24

Active member
Joined
Mar 27, 2008
Messages
35
Programming Experience
3-5
Hello, I have a datagrid in my project and I want to place label controls above each of its columns and those labels should stay above each column even when I resize columns. I need something like "Datagrid.Columns(i).Left", but of course there is no such property. Is there a way to obtain such information?
 

InertiaM

Well-known member
Joined
Nov 3, 2007
Messages
663
Location
Kent, UK
Programming Experience
10+
Take the left position of the grid, and add to it the widths of all the visible columns until you arrive at the column you want :D
 

cjard

Well-known member
Joined
Apr 25, 2006
Messages
7,052
Programming Experience
10+
Hello, I have a datagrid in my project and I want to place label controls above each of its columns and those labels should stay above each column even when I resize columns. I need something like "Datagrid.Columns(i).Left", but of course there is no such property. Is there a way to obtain such information?
These things are called "Column Headers" and are a part of the DataGridView by default, though they can be hidden.

Example:
Here is a datagridview. It has labels above the columns that move and resize with the columns. The labels are ID, Name and Birthday:

 

bufer24

Active member
Joined
Mar 27, 2008
Messages
35
Programming Experience
3-5
Hi guys, I found it at last. I can get the column bounds using:

DataGridView.GetColumnDisplayRectangle(ColumnIndex, CutOverflow)

This function returns the bounding rectangle for a column specified by index.
 
Top Bottom