Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7653903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:08:35+00:00 2026-05-31T12:08:35+00:00

I have put a datagridview into my windows form. I measure width and height

  • 0

I have put a datagridview into my windows form. I measure width and height of the screen and then I draw empty cells on the screen. That works fine, problem is that I don’t know how much cells I can put on my screen depending on width and height. I get a lot more cells then I should. When I draw them I’am getting more cells than size of my screen on my right and on the bottom of my screen.

I’ll put some code so you can see what I am talking about:

public static int height= Screen.PrimaryScreen.Bounds.Height;
public static int width= Screen.PrimaryScreen.Bounds.Width;

public void draw()
{
    number_of_cells_width = width/ 5;  //I have put number 5 because I think they are 5x5 by default size
    number_of_cells_height = height / 5;
    for (int i = 0; i < number_of_cells_width ; i++)
    {
        grid.Columns.Add("", "");
    }
    for (int i = 0; i < number_of_cells_height ; i++)
    {
        grid.Rows.Add("");
    }
}

And I have put datagridview to fill my parent.
So I get a lot more cells then I should. Any idea how to fix this?

I think some dividing should do the job. But I don’t see what I have done wrong.

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T12:08:37+00:00Added an answer on May 31, 2026 at 12:08 pm

    Screen.PrimaryScreen.Bounds.Width Does not take into account the windows title bars etc …

    So you will have to take these elements into account if you want to use this method. Or simply get the size of your DataGridView, and calculate from there ?

    DatagridView1.Height and DatagridView1.Width should come in handy.

    Then just put the code in the correct event, so that you reajust when the window gets resized 🙂

    Edit : the event Resize of the datagridView should suit your needs 🙂

    Edit 2 :

    foreach (DataGridViewColumn col in DataGridView1.Columns) 
    {
        col.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
        col.Width = 5;
    }
    foreach (DataGridViewRow row in DataGridView1.Rows) 
    {
        row.Height = 5;
    }
    

    The following snippet should parse all columns and rows and set their size to 5. So you will have cells 5*5 and columns which dont autosize

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a datagridview that I have put a ContextMenuStrip1 on. I would like
I have a MDI Child Form which contains a DataGridView that is updated continuously
I have created a UserControl in C# that I have put a DataGridView on.
I have a DataGridView in a form that has a data table as the
I have a dataGridView that has a column called Date Due which is of
i have put that url http://pvpcoach.com/notification.php in Instant Payment Notification setting in my profile
I have put together a HTTP driven API using the WCF WebAPI that uses
I have a DataGridView that I'm binding to a DataTable. The DataTable is a
I am working with a WinForms DataGridView control. I have put this control in
In a DataGridView I have a lot of required cells. When saving this DataGridView

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.