IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

DataGridView et Colspan


Sujet :

VB.NET

  1. #1
    Membre chevronné
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mars 2011
    Messages
    453
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2011
    Messages : 453
    Par défaut DataGridView et Colspan
    Bonjour tout le monde,

    je voudrais faire un tableau d'affichage (en ReadOnly donc) pour récapituler un certain nombre de données auprès de l'utilisateur.

    Il faudrait que ça rende ça (en mieux):


    J'ai trouvé du code en C# que j'ai voulu traduire, mais il utilise des types non reconnu en VB (DataGridItem et TableCell).

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    Private Sub DataGrid1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim dgItem As datagriditem = New DataGridItem(0, 0, ListItemType.Header)
            Dim tbCellTableCell = New TableCell()
            tbCell.ColumnSpan = 12 ' Set it to the colspan that you want 
            tbCell.Text = "Category Information"
            tbCell.Attributes.Add("style", "text-align:center")
            dgItem.Cells.Add(tbCell)
            DataGrid1.Controls[0].Controls.AddAt(0, dgItem)
        End Sub
    Donc si quelqu'un c'est déjà confronté au même problème, je suis à l'écoute. Y compris pour utiliser un autre Control que le DataGridView si il en existe un plus approprié...

  2. #2
    Rédacteur/Modérateur


    Homme Profil pro
    Développeur .NET
    Inscrit en
    Février 2004
    Messages
    19 875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2004
    Messages : 19 875
    Par défaut
    Le code que tu as trouvé concerne le DataGrid d'ASP.NET, pas le DataGridView de Windows Forms...

    Je ne pense pas qu'il soit possible de faire l'équivalent d'un "colspan" avec le DataGridView, en tous cas pas de façon simple. Certains contrôles de grille plus évolués le permettent (par exemple XtraGrid de DevExpress), mais ils sont payants...

  3. #3
    Membre chevronné
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mars 2011
    Messages
    453
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2011
    Messages : 453
    Par défaut
    Merci de te pencher sur mon problème

    J'ai trouvé un autre code (encore en C#... et que j'ai traduit) mais là je ne comprends pas exactement comment m'en servir:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    Public Class HMergedCell
        Inherits DataGridViewTextBoxCell
     
        Private m_nLeftColumn As Integer = 0
        Private m_nRightColumn As Integer = 0
     
        ''' <summary>
        ''' Column Index of the left-most cell to be merged.
        ''' This cell controls the merged text.
        ''' </summary>
        ''' <remarks></remarks>
        Public Property LeftColumn() As Integer
            Get
                Return m_nLeftColumn
            End Get
            Set(ByVal value As Integer)
                m_nLeftColumn = value
            End Set
        End Property
     
        ''' <summary>
        ''' Column Index of the right-most cell to be merged
        ''' </summary>
        ''' <remarks></remarks>
        Public Property RightColumn() As Integer
            Get
                Return m_nRightColumn
            End Get
            Set(ByVal value As Integer)
                m_nRightColumn = value
            End Set
        End Property
     
        Protected Overrides Sub Paint(ByVal graphics As Graphics, ByVal clipBounds As Rectangle, ByVal cellBounds As Rectangle, ByVal rowIndex As Integer, ByVal cellState As DataGridViewElementStates, _
                             ByVal value As Object, ByVal formattedValue As Object, ByVal errorText As String, ByVal cellStyle As DataGridViewCellStyle, ByVal advancedBorderStyle As DataGridViewAdvancedBorderStyle, _
                                ByVal paintParts As DataGridViewPaintParts)
     
            Try
                Dim mergeindex As Integer = ColumnIndex - m_nLeftColumn
                Dim i As Integer = 0
                Dim nWidth As Integer = 0
                Dim nWidthLeft As Integer = 0
                Dim strText As String = Nothing
     
                Dim pen As Pen = New Pen(Brushes.Black)
     
                ' Draw the background
                graphics.FillRectangle(New SolidBrush(SystemColors.Control), cellBounds)
     
                ' Draw the separator for rows
                graphics.DrawLine(New Pen(New SolidBrush(SystemColors.ControlDark)), cellBounds.Left, cellBounds.Bottom - 1, cellBounds.Right, _
                                  cellBounds.Bottom - 1)
     
                ' Draw the right vertical line for the cell
                If (ColumnIndex = m_nRightColumn) Then
                    graphics.DrawLine(New Pen(New SolidBrush(SystemColors.ControlDark)), cellBounds.Right - 1, cellBounds.Top, cellBounds.Right - 1, _
                                      cellBounds.Bottom)
                End If
     
                ' Draw the text
                Dim rectDest As RectangleF = RectangleF.Empty
                Dim sf As StringFormat = New StringFormat()
                sf.Alignment = StringAlignment.Center
                sf.LineAlignment = StringAlignment.Center
                sf.Trimming = StringTrimming.EllipsisCharacter
     
                ' Determine the total width of the merged cell
                nWidth = 0
                i = m_nLeftColumn
                Do Until i <= m_nRightColumn
                    nWidth += Me.OwningRow.Cells(i).Size.Width
                    i += 1
                Loop
     
                ' Determine the width before the current cell.
                nWidthLeft = 0
                i = m_nLeftColumn
                Do Until i <= ColumnIndex - 1
                    nWidthLeft += Me.OwningRow.Cells(i).Size.Width
                    i += 1
                Loop
     
                ' Retrieve the text to be displayed
                strText = Me.OwningRow.Cells(m_nLeftColumn).Value.ToString()
     
                rectDest = New RectangleF(cellBounds.Left - nWidthLeft, cellBounds.Top, nWidth, cellBounds.Height)
                graphics.DrawString(strText, New Font("Arial", 10, FontStyle.Regular), Brushes.Black, rectDest, sf)
     
            Catch ex As Exception
                Trace.WriteLine(ex.ToString())
     
            End Try
     
        End Sub
    End Class

  4. #4
    Rédacteur/Modérateur


    Homme Profil pro
    Développeur .NET
    Inscrit en
    Février 2004
    Messages
    19 875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2004
    Messages : 19 875
    Par défaut
    Je sais pas exactement non plus... A priori il faut ajouter une colonne de type HMergedCell au DataGridView, et indiquer les index des colonnes à fusionner

Discussions similaires

  1. [c#] datagridview - trouver postion de la selection
    Par zeroox dans le forum Windows Forms
    Réponses: 7
    Dernier message: 15/04/2009, 12h48
  2. Probleme d'affichage avec un DataGridView
    Par kekesilo dans le forum Windows Forms
    Réponses: 3
    Dernier message: 30/01/2007, 14h12
  3. Ajouter 1 ligne à un tableau avec rowspan & colspan
    Par softflower dans le forum Général JavaScript
    Réponses: 8
    Dernier message: 22/11/2006, 22h35
  4. [CSS] Colspan ?
    Par Mister Nono dans le forum Mise en page CSS
    Réponses: 3
    Dernier message: 02/12/2005, 15h26
  5. [VS2005][VB.Net] Custom Format dans un DataGridView
    Par Vonotar dans le forum VB.NET
    Réponses: 10
    Dernier message: 22/11/2005, 08h15

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo