Solved

want to set column width to the width of the datagridview

Posted on 2014-11-20
3
138 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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