Solved

want to set column width to the width of the datagridview

Posted on 2014-11-20
3
141 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
  • 2
3 Comments
 
LVL 28

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now