?
Solved

want to set column width to the width of the datagridview

Posted on 2014-11-20
3
Medium Priority
?
154 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

771 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