3 Replies - 1733 Views - Last Post: 24 May 2010 - 01:55 AM Rate Topic: -----

#1 km3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 25-May 09

DataGridView

Posted 23 May 2010 - 06:21 AM

Hi all programmers
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.


Is This A Good Question/Topic? 0
  • +

Replies To: DataGridView

#2 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 382
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: DataGridView

Posted 23 May 2010 - 11:04 AM

Actually you need to make your columns and rows fit the datagridview. It will have something to do with AutoSizeColumnsMode. You can also specify the minimum column width and minimum row height... Try playing around with all the settings available for datagridview control.
Was This Post Helpful? 1
  • +
  • -

#3 km3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 25-May 09

Re: DataGridView

Posted 24 May 2010 - 01:50 AM

View PostFlashM, on 23 May 2010 - 10:04 AM, said:

Actually you need to make your columns and rows fit the datagridview. It will have something to do with AutoSizeColumnsMode. You can also specify the minimum column width and minimum row height... Try playing around with all the settings available for datagridview control.


Thanks for the info. I will try to read about the dataGridView and about what you just wrote me.
Was This Post Helpful? 0
  • +
  • -

#4 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 382
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: DataGridView

Posted 24 May 2010 - 01:55 AM

If you need any further help or get stuck on the way, feel free to ask...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1