Set a text in a RowHeader cell

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
 
H

Homer J Simpson

"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)
 
R

ronchese

Hmm I got the point.

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

Thanks.

Cesar
 
G

Guest

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

Homer J Simpson

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.
 
G

Guest

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!
 
H

Homer J Simpson

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 "
 
G

Guest

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 "
 
H

Homer J Simpson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top