Set a text in a RowHeader cell

  • Thread starter Thread starter MSNews
  • Start date Start date
M

MSNews

Hi.

I need to set texts to the row headers of a Datagridview, like we can do with column headers.

For example:

========================================
| COLUMN A | COLUMN B | COLUMN B |
ROW 1 | | | |
ROW 2 | | | |
etc..
========================================
I need to set the Row 1, Row 2, etc, to each row header.

I tryed:
DataGridView1.Rows(i).HeaderCell.Value = "some text"
.... but did not works. No text is displayed

The reason I need to use row header is because I want to enjoy
the header behavior (it automatically changes appearance
on mouse mouse, marks the selected row, etc).

There is some manner to set the text?


Cesar
 
"MSNews" <info(a)carsoftnet.com.br> wrote in message
Hi.

I need to set texts to the row headers of a Datagridview, like we can do
with column headers.

For example:

========================================
| COLUMN A | COLUMN B | COLUMN B |
ROW 1 | | | |
ROW 2 | | | |
etc..
========================================
I need to set the Row 1, Row 2, etc, to each row header.

I tryed:
DataGridView1.Rows(i).HeaderCell.Value = "some text"
.... but did not works. No text is displayed

The reason I need to use row header is because I want to enjoy
the header behavior (it automatically changes appearance
on mouse mouse, marks the selected row, etc).

There is some manner to set the text?

Cesar

' Create a new datagridView control.

datagridView1.Bounds = New Rectangle(New Point(20, 40), New Size(400, 160))

datagridView1.Columns.Add("FED", "FOD")

datagridView1.Rows.Add()

datagridView1.Rows(0).Cells(0).Value = "FOO"

datagridView1.Rows(0).HeaderCell.Value = "SOP"

Me.Controls.Add(datagridView1)
 
Hmm I got the point.

We must to use a data-unbound grid to can change the header cell.

Thanks.

Cesar
 
Can you also tell how to set the width of this column? so whatever text you
put there will be visible?
 
Can you also tell how to set the width of this column? so whatever text
you
put there will be visible?

Set the width to -1 or -2 and it will fit the data or the title.
 
Width of what?
The closest thing was
this.dataGridView1.Rows[0].HeaderCell.OwningColumn.Width but
this.dataGridView1.Rows[0].HeaderCell.OwningColumn is null
I can't figure out the column of the headercells
Column[-1] is an error!
 
Width of what?
The closest thing was
this.dataGridView1.Rows[0].HeaderCell.OwningColumn.Width but
this.dataGridView1.Rows[0].HeaderCell.OwningColumn is null
I can't figure out the column of the headercells
Column[-1] is an error!

See "DataGridView control [Windows Forms], column sizing"

IIRC, it's DataGridView1.Columns(1).Width = -1 (but I coud be wrong)

Also see "How to: Set the Sizing Modes of the Windows Forms DataGridView
Control "
 
DataGridView1.Columns(1) is the second "Real" column in the grid!

I want to reference the grey column before it (-1) where you told the guy to
use
HeaderCell.Value
I looked in the Set the Sizing Modes of the Windows Forms DataGridView but
it does not reference this column.

Homer J Simpson said:
Width of what?
The closest thing was
this.dataGridView1.Rows[0].HeaderCell.OwningColumn.Width but
this.dataGridView1.Rows[0].HeaderCell.OwningColumn is null
I can't figure out the column of the headercells
Column[-1] is an error!

See "DataGridView control [Windows Forms], column sizing"

IIRC, it's DataGridView1.Columns(1).Width = -1 (but I coud be wrong)

Also see "How to: Set the Sizing Modes of the Windows Forms DataGridView
Control "
 
I want to reference the grey column before it (-1) where you told the guy
to
use
HeaderCell.Value
I looked in the Set the Sizing Modes of the Windows Forms DataGridView but
it does not reference this column.

Did you try

DataGridView1.RowHeadersWidthSizeMode = AutoSizeToAllHeaders
 
Back
Top