views:

337

answers:

3

I was wondering whether it is possible to remove the unused space ( the gray space ) of the DataGridView control in C#. I have to make the DataGridView display the white table only.

alt text

Any suggestions ?

+1  A: 

I believe you want:

myDataGrid.AutoSizeColumnsMode = Fill

EDIT: This just resizes the columns. I'm not sure how you would get rid of row gray space other than resizing the grid's height.

smoore
This won't get rid of all the grey space, just the space to the right of the columns. You'll have to write a handler for the Resize event to size the visible rows to fill the grid if you want that behavior.
Ron Warholic
With your edit you're incorrect in assuming there is a fill value for AutoSizeRowsMode.
Ron Warholic
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewautosizerowsmode.aspx
Refracted Paladin
@Sid Farkus I just saw the AutoSizeRowsMode property and assumed it did the same things as the AutoSizeColumnsMode property. I had never actually tried the AutoSizeRowsMode. Sorry about that.
smoore
A: 

Set the RowsHeaderVisible property to false, you can either do that from the designer, in category Appearence, or from the code :

dataGridView1.RowsHeaderVisible = false;

In order to remove the indicator row on the left side, as for the rest of the grey space, you can try set the aforementionned AutoSizeColumnsMode to Fill, but you will still have the lower part grayed out from lack of rows.

Instead of sizing your cells to fill your grid, you could resize your grid in order to fit around your cells. Whether or not this is an acceptable approach will depend on your intent.

I mean, it's possible that if its just the color that is bothering you, setting the backcolor to white would do the trick.

Dynami Le Savard
A: 
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
codemonkie