Results 1 to 4 of 4

Thread: [2005] DataGridView - AllowUserToResizeColumns property

  1. #1

    Thread Starter
    Fanatic Member snufse's Avatar
    Join Date
    Jul 2004
    Location
    Jupiter, FL
    Posts
    912

    [2005] DataGridView - AllowUserToResizeColumns property

    I have a windows from with two data grid views. They both have the property AllowUserToResizeColumns = True, one let's me resize the column, the other one not. Any clues?

  2. #2
    Junior Member
    Join Date
    Jun 2002
    Posts
    29

    Re: [2005] DataGridView - AllowUserToResizeColumns property

    Hiya

    I had a problem like this, when I set the DataGridView to AutoSizeColumnsMode.AllCells the columns were not resizable, even though I had set the AllowUserToResizeColumns to True. There wasnt much out there about this so i did the following, it aint pretty but it worked for me and hopefully it will help someone else: essentially, you set the AutoSizeColumnsMode mode to AllCells, then measure the width of each column, then set AutoSizeColumnsMode back to None and reset the width of all of the columns.

    Code:
                
    DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
    DataGridView1.AllowUserToResizeColumns = True
    DataGridView1.DataSource = oDataSet.Tables(0).DefaultView
    
    Dim IntArray(100) As Integer
    Dim i As Integer = 0
    Dim oColumn As DataGridViewColumn
    
    For Each oColumn In DataGridView1.Columns
        IntArray(i) = oColumn.Width
        i = i + 1
    Next
    i = 0
    DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None
    For Each oColumn In DataGridView1.Columns
        oColumn.Width = IntArray(i)
        i = i + 1
    Next

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] DataGridView - AllowUserToResizeColumns property

    Why would you autosize the columns at all if you intend to let the user size the columns as they want? The two have different aims.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Thumbs up Re: [2005] DataGridView - AllowUserToResizeColumns property

    Excellent solution fatbloke to a problem that still exists 6 years later.
    ~Peter


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width