Groups | Blog | Home
all groups > vb.net controls > january 2005 >

vb.net controls : Datagrid Column widths (VB.NET)


spongebob-straight-pants
1/23/2005 3:05:31 PM
Hi,
I apologize if this was discussed before but I could not find a solution
that worked by looking through these NGs.

If I made the DG resizeable, the user resizes it in run time and the form is
reloaded, the column widths are setting back to their default values. How
would I prevent that (in other words, have the resized width persist??)

I tried this code with a module level variable marr() but I have no idea on
where to place this code? Is there a resize event that fires when the
columns are resized? There is a resize event but that does not get fired
when the columns are resized.

'Dim idx As Integer

'With dgLocations.TableStyles(0)

' ReDim marrCol(.GridColumnStyles.Count - 1)

' For idx = 0 To .GridColumnStyles.Count - 1

' marrCol(idx) = .GridColumnStyles(idx).Width

' Next idx

'End With



Ken Tucker [MVP]
1/24/2005 7:17:08 AM
Hi,

Try something like this is the datagrid mouse move
event.


Private Sub DataGrid1_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseMove

Dim hti As DataGrid.HitTestInfo

hti = DataGrid1.HitTest(e.X, e.Y)

If hti.Type = DataGrid.HitTestType.ColumnResize Then

Debug.WriteLine(String.Format("Resized Column {0}", hti.Column))

End If

End Sub



Ken

-------------------


[quoted text, click to view]
Hi,
I apologize if this was discussed before but I could not find a solution
that worked by looking through these NGs.

If I made the DG resizeable, the user resizes it in run time and the form is
reloaded, the column widths are setting back to their default values. How
would I prevent that (in other words, have the resized width persist??)

I tried this code with a module level variable marr() but I have no idea on
where to place this code? Is there a resize event that fires when the
columns are resized? There is a resize event but that does not get fired
when the columns are resized.

'Dim idx As Integer

'With dgLocations.TableStyles(0)

' ReDim marrCol(.GridColumnStyles.Count - 1)

' For idx = 0 To .GridColumnStyles.Count - 1

' marrCol(idx) = .GridColumnStyles(idx).Width

' Next idx

'End With




spongebob-straight-pants
1/24/2005 6:34:18 PM
Nope. This don't work...

[quoted text, click to view]

spongebob-straight-pants
1/24/2005 6:47:25 PM
That did not work however, the following worked:
If hti.Type = DataGrid.HitTestType.ColumnHeader Then



Thanks






[quoted text, click to view]

AddThis Social Bookmark Button