I think i'm going nuts... Hahaha.
Here's the story. I've been programming in VBA for the past couple of years, but now i'm trying to dive into the VB.NET language via the Visual Basic 2005 Express Programming Enviroment. I started out with a project i called "StopWatch" where i could monitor time spent on an activity. What started out as a simple form soon became a mdiParent with several Childeren. One of them is the "StopWatch" form i started out with, one of them is a "Logging" form with a RichTextBox and a DataGridView control, keeping track of the time which has been logged by the "StopWatch" form.
The thing is, the DataGridView contains 2 columns, one column with a description of the item in question (like for instance "Recorded Time:") and one with the value logged by the "StopWatch" form. The DataGridView has been set to AutoSize, so that the column width would change depending on the size of the text. However, what i would like to do is automatically resizing the DataGrid so that it would fill the entire form.
Everytime i try to adjust the width of either of the columns, the application simply ignores me and does not change the column width. If i were to place a breakpoint/Watch onto the section where i change the column width you can see that the value appears to be Read-Only. Only, the DataGrid does have the "Read-Only = False" property set up.
Here's a snippet of the "mdiMAIN" form, which is the Main form for the entire application:
Private Sub mdiMAIN_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'frmDump.WindowState = FormWindowState.MaximizedfrmDump.dgvDump.ColumnCount = 2
With frmDump.dgvDump.ColumnHeadersDefaultCellStyle.BackColor = Color.Navy
.ForeColor = Color.White
.Font =
New Font(frmDump.dgvDump.Font, FontStyle.Bold) End With With frmDump.dgvDump '.AutoSizeRowsMode = _ 'DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders '.RowHeadersVisible = False.BorderStyle = BorderStyle.None
.Columns(0).Name =
"Section".Columns(0).DefaultCellStyle.Font = _
New Font(frmDump.dgvDump.DefaultCellStyle.Font, FontStyle.Bold).Columns(0).DefaultCellStyle.BackColor = Color.AliceBlue
.Columns(1).Name =
"Information".Columns(1).DefaultCellStyle.Font = _
New Font(frmDump.dgvDump.DefaultCellStyle.Font, FontStyle.Italic).Columns(0).SortMode = DataGridViewColumnSortMode.Programmatic
.Columns(1).SortMode = DataGridViewColumnSortMode.Programmatic
Dim column As DataGridViewColumn = .Columns(0)column.Width = 200
End WithfrmDump.rtbDump.Visible =
FalsePlainTextToolStripMenuItem.Checked =
FalsefrmDump.dgvDump.Visible =
TrueGridViewToolStripMenuItem.Checked =
TruefrmDump.MdiParent =
MefrmDump.Show()
'Me.LayoutMdi(MdiLayout.TileVertical) End SubIf i were to place a Breakpoint/Watch on the "column.with = 200" line, the value of Column will not be changed and remain on 100 if i leave the "With" statement via the F8 key.
If you would like to take a look at the entire code, please let me know so that i can send the entire source code via e-mail, or something. (^_~ ) (I can't seem to find an "Attachment" section on this forum)

Datagrid: Auto Resize to UserForm.width
swemaniac
livingsingl
MartinKrieger
Thanks for the tip Ken.
I implemented both the ".dock = DocStyle.Fill" as well as the ".anchor = AnchorStyle.Left" into the form in question, however that didn't solve the problem at hand. The size of the column still remained the same, even after trying to adjust it via ".columns(x).with = me.with". (T_T )
So i figured that it might be some kind of setting i keep overlooking. That's when i started a new Project and created one single form with a standard DataGridView in it. I incorperated the ".dock = DocStyle.Fill" command and tried again. This time, the datagridview accepted the width adjustments i placed into my code. That when i knew for certain i overlooked something in my Project.
After recreating the DataGridView into the Logging form and walking through each setting i finally found the culprit... The "AutoSizeColumnMode" was set to "AllCellsExceptHeaders". When i changed that setting to "None", the problem was solved. (-_-; )
On the other hand, due to the tip you gave me i solved a "Newbie" issue i had with my application. Since i've been programming in VBA, i've always been handicapped with fixed sizes. If i wanted to create a form or a control with a dynamic size, i needed to calculate the new size of the form/control and supply the designated form/control with the new measurements via code. I also did this in my VB.NET application via by using the SizeChanged property of a form. Then i'd supply the DataGridView with a "me.widht" minus the form borders. Thanks to the ".Dock" property, that issue is replaced with a simple click from the From Designer View. (^_^ )-b
Thanks for the tip! m-(_ _)-m