> For i As Integer = 1 To Me.g.Columns.Count > Me.g.Columns(i - 1).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells > Next >>this does not give me the total width of the grid:
> Dim w As Integer = 0 > For Each col As DataGridViewColumn In Me.g.Columns > w = +col.Width + 1 > Next >>
> Private Sub TxtBase1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TxtBase1.Validating > > Dim c As String = "select kl_nummer,Kl_naam from Klanten where kl_Naam like '%" & Me.TxtBase1.Text & "%'" > Dim s As New sqlClass : Dim tally As Integer = s.Execute(c) > > Dim o As New PopupFrm > o.dt = s.dt > o.caller = Me.TxtBase1 > o.ShowDialog() > MsgBox(o.Name) > MsgBox(o.g(0, o.g.CurrentRow.Index).FormattedValue) > > End Sub >>
>Public Class PopupFrm > Public dt As DataTable > Public caller As Control > Public userCanceled As Boolean > Private Sub PopupFrm_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress > If e.KeyChar = ChrW(27) Then > Me.userCanceled = True > End If > Me.Close() > End Sub > > Private Sub PopupFrm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load > Dim f As Form = Me.caller.FindForm > Me.Top = Me.caller.Top + f.Top > Me.Left = Me.caller.Left + f.Left + Me.caller.Width > Me.g.Top = 0 > Me.g.Left = 0 > Me.g.RowHeadersVisible = False > Me.g.ColumnHeadersVisible = False > Me.g.DefaultCellStyle.Font = New Font(FontFamily.GenericSansSerif, 8.25F, FontStyle.Bold) > Me.g.GridColor = Color.LightGray > Me.g.SelectionMode = DataGridViewSelectionMode.FullRowSelect > Me.g.DefaultCellStyle.BackColor = Color.Turquoise > Me.g.DataSource = Me.dt > For i As Integer = 1 To Me.g.Columns.Count > Me.g.Columns(i - 1).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells > Next > End Sub > > Private Sub PopupFrm_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown > Dim w As Integer = 0 > For Each col As DataGridViewColumn In Me.g.Columns > w = +col.Width + 1 > Next > Me.g.Width = w > Me.Width = w + 2 > Me.g.Height = Math.Min(10, Me.dt.Rows.Count) * (Me.g.RowTemplate.Height + 1) > Me.Height = Me.g.Height + 2 > End Sub >End Class >w = +col.Width + 1 is very different to w+=col.Width+1.......