Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. WinForms - DataGridView AutoResizeColumns not working.

WinForms - DataGridView AutoResizeColumns not working.

Scheduled Pinned Locked Moved C#
csharpwpfwinformswcfgraphics
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sir Dot Net
    wrote on last edited by
    #1

    I have a simple class (just contains automatic properties, nothing special), and a Form w/ a datagridview on it. It is binding directly to the class, and is working fine in every respect, however I want to autosize the columns to the data within them after bind (but retain it's current column sizing mode of 'None' afterwords so the user can resize them) I call AutoResizeColumns and pass DataGridViewAutoSizeColumnsMode.DisplayedCells (I've also tried 'AllCells'). The datagrid doesn't resize though! Am I missing something?

    private void PopulateUI() {
    this.dataGridViewHistory.AutoGenerateColumns = false;
    this.dataGridViewHistory.DataSource = this.Project.Modifications;
    //the next line doesn't appear to do anything
    this.dataGridViewHistory.AutoResizeColumns( DataGridViewAutoSizeColumnsMode.DisplayedCells );
    }

    //
    // dataGridViewHistory initialization code (from designer.cs)
    //
    this.dataGridViewHistory.AllowUserToAddRows = false;
    this.dataGridViewHistory.AllowUserToDeleteRows = false;
    this.dataGridViewHistory.AllowUserToOrderColumns = true;
    dataGridViewCellStyle1.BackColor = System.Drawing.Color.PapayaWhip;
    this.dataGridViewHistory.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1;
    this.dataGridViewHistory.ColumnHeadersHeightSizeMode =
    System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
    this.dataGridViewHistory.Columns.AddRange( new System.Windows.Forms.DataGridViewColumn[] {
    this.ColumnUserID,
    this.ColumnUserName,
    this.ColumnDate,
    this.ColumnFileName} );
    this.dataGridViewHistory.Dock = System.Windows.Forms.DockStyle.Fill;
    this.dataGridViewHistory.Location = new System.Drawing.Point( 6, 16 );
    this.dataGridViewHistory.Name = "dataGridViewHistory";
    this.dataGridViewHistory.ReadOnly = true;
    this.dataGridViewHistory.RowHeadersVisible = false;
    this.dataGridViewHistory.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
    this.dataGridViewHistory.Size = new System.Drawing.Size( 550, 236 );
    this.dataGridViewHistory.TabIndex = 0;

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups