I have a DataGridView populated from a DataSource with the code:
-
Dim dt As New DataTable
-
dt.Columns.Add("Name")
-
dt.Columns.Add("Result")
-
Dim dr As DataRow
-
For i = 1 To 12
-
dr = dt.NewRow()
-
dr(0) = "Name " & i.ToString()
-
dr(1) = "Result " & i.ToString()
-
dt.Rows.Add(dr)
-
Next
-
grd.DataSource = dt
-
The grid is anchored so that it resized together with the form. I want to resize one of the columns when the grid resizes. I'm using the code:
-
Private Sub grd_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles grd.Resize
-
colName.Width = grd.Width - colResult.Width - 18
-
End Sub
-
This has no effect (column is not resizing).
I have tested with populating the grid without a DataSource, using the code:
-
For i = 1 To 12
-
n = grd.Rows.Add()
-
grd.Rows(n).Cells(0).Value = "Name" & i.ToString()
-
grd.Rows(n).Cells(1).Value = "Result" & i.ToString()
-
Next
-
In this case, resizing works fine. However, I need to use a DataSource.
Could someone help ?