Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How can I determine the width of a datagridview
Message
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Titre:
How can I determine the width of a datagridview
Versions des environnements
Environment:
VB 8.0
OS:
Vista
Network:
Windows XP
Database:
Jet/Access Engine
Application:
Desktop
Divers
Thread ID:
01497843
Message ID:
01497843
Vues:
88
For some reason after I do this ...
        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
Here's the calling sequence of a generic popup form :
   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
.. and here's the class itself.... It appears fine, except for the width.
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

If things have the tendency to go your way, do not worry. It won't last. Jules Renard.
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform