Solved

want to set column width to the width of the datagridview

Posted on 2014-11-20
3
146 Views
Last Modified: 2014-11-26
Hello Experts,

I have a datagridview. It populates with the records from the database. There are only four columns. I want the columns to fit into the length of the gridview. I tried AutosizeColumnsMode to 'Fill' but it is not working.

Thank you.
0
Comment
Question by:RadhaKrishnaKiJaya
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 29

Expert Comment

by:sammySeltzer
ID: 40457314
I think that in addition to AutoSizeColumnsMode.Fill, you will also need to do it for all cells.

Something like:

AutosizeColumnsMode.AllCells
0
 

Accepted Solution

by:
RadhaKrishnaKiJaya earned 0 total points
ID: 40457815
Thank you vary much for your reply. But I found the solution.

Public Shared Sub Set_Grid_Width(myGridView As DataGridView)
        myGridView.ColumnHeadersDefaultCellStyle.WrapMode = False

        For i As Integer = 0 To myGridView.Columns.Count - 1
            If i = myGridView.Columns.Count - 2 Then
                myGridView.Columns(i).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
            Else
                myGridView.Columns(i).AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells
            End If
        Next i
    End Sub
End Class
0
 

Author Closing Comment

by:RadhaKrishnaKiJaya
ID: 40466478
I found the solution by myself.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question