I have a dataGridView which has 16 rows and 16 columns. How can I make my dataGridView fit excactly to my rows and columns.? I mean is it possible to make my DataGridView have the excact size so it fits to my rows and columns.
At the moment there is some space after last row and some space after last column witch is not ok. Please help me with this problem.
public void SetUpDataGridView(DataGridView dg)
{
dg.ColumnCount = 17;
//ddg.ColumnHeadersHeight = 1;
dg.ColumnHeadersVisible = false;
dg.RowHeadersVisible = false;
dg.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;//(DataGridViewAutoSizeColumnsMode)1;
dg.AllowUserToResizeColumns = false;
dg.AllowUserToResizeRows = false;
dg.BackgroundColor = this.BackColor;
dg.BorderStyle = BorderStyle.None;
// Set the column header style.
DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
columnHeaderStyle.BackColor = Color.Gray;
//columnHeaderStyle.Font = gcnew System.Drawing.Font( "Verdana",8,FontStyle.Bold );
dg.ColumnHeadersDefaultCellStyle = columnHeaderStyle;
// Default cell style
DataGridViewCellStyle columnStyle = new DataGridViewCellStyle();
columnStyle.Font = new System.Drawing.Font( "Verdana", 7, FontStyle.Regular);
dg.DefaultCellStyle = columnStyle;
// Populate the rows.
String[] row1 = new String[]{"0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"};
for( int i = 0; i < 17; i++ )
{
dg.Rows.Add( row1 );
}
//dg.ColumnHeadersDefaultCellStyle = ;
for( int i = 0; i < 17; i++ )
{
dg.Columns[i].Width = 41;// Width(40);
dg.Rows[i].Height = 14;
}
dg.Rows[0].Cells[0].Style = columnHeaderStyle;
dg.Rows[0].Cells[0].Value = "";
// x/y axis style
DataGridViewCellStyle axisStyle = new DataGridViewCellStyle();
axisStyle.BackColor = Color.LightGray;
axisStyle.Font = new System.Drawing.Font( "Verdana", 7, FontStyle.Bold);
for(int i = 1; i < 17; i++)
{
// x-axis
dg.Rows[0].Cells[i].Style = axisStyle;
// y-axis
dg.Rows[i].Cells[0].Style = axisStyle;
}
//dg.Rows[12].Cells[12].Value = "" + ( System.Int32.Parse(dg.Rows[0].Cells[1].Value.ToString()) + System.Int32.Parse(dg.Rows[1].Cells[0].Value.ToString()) );
}
This post has been edited by JackOfAllTrades: 23 May 2010 - 07:16 AM
Reason for edit:: Added code tags.

New Topic/Question
Reply




MultiQuote




|