Re: DataGridView first column

J

Jack Jackson

When I display a DataGridView on a windows form, there is a left-most column
which is added by the system, the purpose of which appears to be to put a
small triangle pointing to which row is currently activated by the user. The
user can change the column width of this column. How do I access this column
programatically? Most specifically, how can I change its column width in my
program, and is there a way of hiding (i.e. make Visible=False) this column?
I'm using VB in VS 2008.

That is the row header. There are 5 properties of the DataGridView
that deal with how it is displayed, all begin with "RowHeader".
RowHeadersVisible controls whether or not the row header is displayed.

Some (and perhaps all) of the various events that deal with cells
(such as CellFormatting) get called with a column number of -1 for the
row header, which would allow you to have some control over how it is
displayed, to notice when the user clicks in it, etc.
 
E

Ed White

Thanks...I see various RowHeader properties of the dgv, including
RowHeaderVisible and RowHeaderWidth, so that answers my question.
FYI--trying to access column -1 resulted in an error ("... index must be
non-negative").
 
E

Ed White

I have a related question. When the dgv is shown on a form, and I put
another control (e.g. a label) to the right of it, it appears that there is
some space that the dgv takes up to the right of its right-most column (it
covers up the left part of label to the right of it), but it doesn't show
anything, it's just dead space. Is there anyway to get rid of this so I can
put something else in this space?
 
J

Jack Jackson

That's because it isn't a real column. As I said, you can manipulate
it somewhat in the various cell events, but not directly.
 
J

Jack Jackson

I don't see that. Are you sure the DataGridView is not wider than the
column? Is the "dead space" the same color as the form background, or
is it darker? If it's darker, then the DataGridView is wider than the
column. Either make the DataGridView narrower or the column wider.
 
E

Ed White

I'm using AutoSize=True for the DataGridView (dgv). The dead space has the
same color as the dgv.BackgroundColor.
 

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