begin process at 2012 02 12 17:17:55
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

VB.NET

 > DATAGRIDCOLUMNSTYLE AVEC N'IMPORTE QUEL CONTRÔLE: MAJ (3°)

DATAGRIDCOLUMNSTYLE AVEC N'IMPORTE QUEL CONTRÔLE: MAJ (3°)


 Information sur la source

Note :
7,75 / 10 - par 12 personnes
7,75 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :VB.NET Source .NET ( DotNet ) Niveau :Initié Date de création :02/12/2003 Date de mise à jour :12/12/2003 14:50:45 Vu / téléchargé :8 806 / 856

Auteur : CeTjsMoi

Ecrire un message privé
Site perso
Commentaire sur cette source (20)
Ajouter un commentaire et/ou une note

 Description

Cette classe permet de mettre n'importe quel contrôle dans le mode édition de la datagrid et de choisir le type de donnée de la colonne.

La propriété Value ou Text (si Value pas trouvée) de ce contrôle contient automatiquement la valeur de la cellule de la datagrid

Dernière Maj: Correction de la gestion du Null (encore)
- Prise en compte d'une propriété de valeur minimale  pour le control de saisi
   ex: Le datetimepicker possède une propriété DateMin, si les valeurs sont inférieurs à cette propriété, ca casse. Il suffit d'indiquer le nom de cette propriété dans le constructeurs pour que ca fonctionne (attention à la casse du nom de la propriété)

Source

  • Public Class DataGridControlColumn
  • Inherits System.Windows.Forms.DataGridColumnStyle
  • #Region "Variables"
  • Private _xMargin As Integer = 2
  • Private _yMargin As Integer = 1
  • Private _Control As System.Windows.Forms.Control
  • Private _OldVal As String = String.Empty
  • Private _InEdit As Boolean = False
  • Public InnerControlType As Type
  • Public ColumnDataType As Type
  • Public MinimumValuePropertyName As String
  • #End Region
  • #Region "Constructeurs"
  • Public Sub New(ByVal TypeOfInnerControl As Type, ByVal MappingName As String, ByVal ColumnDataType As Type, ByVal Alignement As System.Windows.Forms.HorizontalAlignment, ByVal HeaderText As String, ByVal NullText As String, ByVal Width As Int32, Optional ByVal MinimumValuePropertyName As String = "")
  • MyClass.New(TypeOfInnerControl, MappingName, ColumnDataType, MinimumValuePropertyName)
  • MyBase.Alignment = Alignement
  • MyBase.HeaderText = HeaderText
  • MyBase.MappingName = MappingName
  • MyBase.NullText = NullText
  • MyBase.Width = Width
  • End Sub
  • Public Sub New(ByVal TypeOfInnerControl As Type, ByVal MappingName As String, ByVal ColumnDataType As Type, Optional ByVal MinimumValuePropertyName As String = "")
  • MyClass.ColumnDataType = ColumnDataType
  • MyClass.InnerControlType = TypeOfInnerControl
  • MyBase.MappingName = MappingName
  • MyClass._Control = Activator.CreateInstance(Me.InnerControlType)
  • MyClass._Control.Visible = False
  • MyClass.MinimumValuePropertyName = MinimumValuePropertyName
  • End Sub
  • #End Region
  • Public Property InnerControl() As System.Windows.Forms.Control
  • Get
  • Return MyClass._Control
  • End Get
  • Set(ByVal Value As System.Windows.Forms.Control)
  • MyClass._Control = Value
  • End Set
  • End Property
  • #Region "Heritage de DataGridColumnStyle"
  • Protected Overloads Overrides Sub Abort(ByVal RowNum As Integer)
  • MyClass.RollBack()
  • MyClass.HideForm()
  • MyClass.EndEdit()
  • End Sub
  • Protected Overloads Overrides Function Commit(ByVal DataSource As System.Windows.Forms.CurrencyManager, ByVal RowNum As Integer) As Boolean
  • Try
  • MyClass.HideForm()
  • If Not MyClass._InEdit Then Return True
  • Dim Value As Object
  • Dim Prop As Reflection.PropertyInfo = MyClass._Control.GetType.GetProperty("Value")
  • If Prop Is Nothing Then
  • Value = MyClass._Control.Text
  • Else
  • Value = Prop.GetValue(MyClass._Control, Nothing)
  • End If
  • If NullText.Equals(MyClass.GetText(Value)) Then
  • Value = System.DBNull.Value
  • MyBase.SetColumnValueAtRow(DataSource, RowNum, MyClass.NullText)
  • Else
  • Value = Convert.ChangeType(Value, MyClass.ColumnDataType)
  • If Value.GetType Is MyClass.ColumnDataType Then
  • MyBase.SetColumnValueAtRow(DataSource, RowNum, Value)
  • Else
  • Return False
  • End If
  • End If
  • Catch e As Exception
  • MyClass.RollBack()
  • Return False
  • End Try
  • MyClass.EndEdit()
  • Return True
  • End Function
  • Protected Overloads Overrides Sub ConcedeFocus()
  • MyClass._Control.Visible = False
  • End Sub
  • Protected Overloads Overrides Sub Edit(ByVal Source As System.Windows.Forms.CurrencyManager, ByVal Rownum As Integer, ByVal Bounds As System.Drawing.Rectangle, ByVal [ReadOnly] As Boolean, ByVal InstantText As String, ByVal CellIsVisible As Boolean)
  • If Not InstantText Is Nothing Then
  • MyClass._Control.Text = InstantText
  • Else
  • MyClass._Control.Text = MyClass.GetText(MyBase.GetColumnValueAtRow(Source, Rownum))
  • End If
  • Dim OriginalBounds As System.Drawing.Rectangle = Bounds
  • MyClass._OldVal = MyClass._Control.Text
  • If CellIsVisible Then
  • Bounds.Offset(MyClass._xMargin, MyClass._yMargin)
  • Bounds.Width -= MyClass._xMargin * 2
  • Bounds.Height -= MyClass._yMargin
  • MyClass._Control.Bounds = Bounds
  • MyClass._Control.Visible = True
  • Else
  • MyClass._Control.Bounds = OriginalBounds
  • MyClass._Control.Visible = False
  • End If
  • MyClass._Control.RightToLeft = MyBase.DataGridTableStyle.DataGrid.RightToLeft
  • MyClass._Control.Focus()
  • If MyClass._Control.Visible Then
  • MyBase.DataGridTableStyle.DataGrid.Invalidate(OriginalBounds)
  • End If
  • MyClass._InEdit = True
  • End Sub
  • #Region "Gestion des Tailles"
  • Protected Overloads Overrides Function GetMinimumHeight() As Integer
  • Return 25 'todo MyClass._Panel.PreferredHeight + MyClass._yMargin
  • End Function
  • Protected Overloads Overrides Function GetPreferredHeight(ByVal g As System.Drawing.Graphics, ByVal Value As Object) As Integer
  • Dim NewLineIndex As Integer = 0
  • Dim NewLines As Integer = 0
  • Dim ValueString As String = MyClass.GetText(Value)
  • Do
  • While NewLineIndex <> -1
  • NewLineIndex = ValueString.IndexOf("r\n", NewLineIndex + 1)
  • NewLines += 1
  • End While
  • Loop
  • Return MyBase.FontHeight * NewLines + MyClass._yMargin
  • End Function
  • Protected Overloads Overrides Function GetPreferredSize(ByVal g As System.Drawing.Graphics, ByVal Value As Object) As System.Drawing.Size
  • Dim Extents As System.Drawing.Size = System.Drawing.Size.Ceiling(g.MeasureString(MyClass.GetText(Value), MyBase.DataGridTableStyle.DataGrid.Font))
  • Extents.Width += MyClass._xMargin * 2 + MyClass.DataGridTableGridLineWidth
  • Extents.Height += MyClass._yMargin
  • Return Extents
  • End Function
  • #End Region
  • #Region "Méthodes Paint"
  • Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing.Graphics, ByVal Bounds As System.Drawing.Rectangle, ByVal Source As System.Windows.Forms.CurrencyManager, ByVal RowNum As Integer)
  • MyClass.Paint(g, Bounds, Source, RowNum, False)
  • End Sub
  • Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing.Graphics, ByVal Bounds As System.Drawing.Rectangle, ByVal Source As System.Windows.Forms.CurrencyManager, ByVal RowNum As Integer, ByVal AlignToRight As Boolean)
  • Dim Text As String = MyClass.GetText(MyBase.GetColumnValueAtRow(Source, RowNum))
  • MyClass.PaintText(g, Bounds, Text, AlignToRight)
  • End Sub
  • Protected Overloads Sub Paint(ByVal g As System.Drawing.Graphics, ByVal Bounds As System.Drawing.Rectangle, ByVal Source As System.Windows.Forms.CurrencyManager, ByVal RowNum As Integer, ByVal BackBrush As System.Drawing.Brush, ByVal ForeBrush As System.Drawing.Brush, ByVal AlignToRight As Boolean)
  • Dim Text As String = MyClass.GetText(MyBase.GetColumnValueAtRow(Source, RowNum))
  • MyClass.PaintText(g, Bounds, Text, BackBrush, ForeBrush, AlignToRight)
  • End Sub
  • #End Region
  • Protected Overloads Overrides Sub SetDataGridInColumn(ByVal Value As System.Windows.Forms.DataGrid)
  • MyBase.SetDataGridInColumn(Value)
  • If Not (MyClass._Control.Parent Is Value) Then
  • If Not (MyClass._Control.Parent Is Nothing) Then
  • MyClass._Control.Parent.Controls.Remove(MyClass._Control)
  • End If
  • End If
  • If Not (Value Is Nothing) Then
  • 'MyClass._Control.Owner = Value.FindForm
  • Value.Controls.Add(MyClass._Control)
  • End If
  • End Sub
  • Protected Overloads Overrides Sub UpdateUI(ByVal Source As System.Windows.Forms.CurrencyManager, ByVal RowNum As Integer, ByVal InstantText As String)
  • MyClass._Control.Text = MyClass.GetText(MyBase.GetColumnValueAtRow(Source, RowNum))
  • If Not (InstantText Is Nothing) Then
  • MyClass._Control.Text = InstantText
  • End If
  • End Sub
  • #End Region
  • #Region "Méthodes privées"
  • Private ReadOnly Property DataGridTableGridLineWidth() As Integer
  • Get
  • If MyBase.DataGridTableStyle.GridLineStyle = System.Windows.Forms.DataGridLineStyle.Solid Then
  • Return 1
  • Else
  • Return 0
  • End If
  • End Get
  • End Property
  • Private Sub EndEdit()
  • MyClass._InEdit = False
  • MyBase.Invalidate()
  • End Sub
  • Private Function GetText(ByVal Value As Object) As String
  • If MyClass.MinimumValuePropertyName <> String.Empty Then
  • Dim Prop As Reflection.PropertyInfo = MyClass._Control.GetType.GetProperty(MyClass.MinimumValuePropertyName)
  • If Not Prop Is Nothing Then
  • Dim Obj As Object = Convert.ChangeType(Prop.GetValue(MyClass._Control, Nothing), MyClass.ColumnDataType)
  • If Value.compareto(Obj) < 0 Then Value = Obj
  • End If
  • End If
  • If Value Is System.DBNull.Value Then Return NullText
  • If Not Value Is Nothing Then
  • Return Value.ToString
  • Else
  • Return NullText
  • End If
  • End Function
  • Private Sub HideForm()
  • If MyClass._Control.Focused Then
  • MyBase.DataGridTableStyle.DataGrid.Focus()
  • End If
  • MyClass._Control.Visible = False
  • End Sub
  • Private Sub RollBack()
  • MyClass._Control.Text = MyClass._OldVal
  • End Sub
  • Private Sub PaintText(ByVal g As System.Drawing.Graphics, ByVal Bounds As System.Drawing.Rectangle, ByVal Text As String, ByVal AlignToRight As Boolean)
  • Dim BackBrush As System.Drawing.Brush = New System.Drawing.SolidBrush(MyBase.DataGridTableStyle.BackColor)
  • Dim ForeBrush As System.Drawing.Brush = New System.Drawing.SolidBrush(MyBase.DataGridTableStyle.ForeColor)
  • MyClass.PaintText(g, Bounds, Text, BackBrush, ForeBrush, AlignToRight)
  • End Sub
  • Private Sub PaintText(ByVal g As System.Drawing.Graphics, ByVal TextBounds As System.Drawing.Rectangle, ByVal Text As String, ByVal BackBrush As System.Drawing.Brush, ByVal ForeBrush As System.Drawing.Brush, ByVal AlignToRight As Boolean)
  • Dim Rect As System.Drawing.Rectangle = TextBounds
  • Dim RectF As System.Drawing.RectangleF = System.Drawing.RectangleF.op_Implicit(Rect) ' Convert to RectangleF
  • Dim Format As System.Drawing.StringFormat = New System.Drawing.StringFormat()
  • If AlignToRight Then Format.FormatFlags = System.Drawing.StringFormatFlags.DirectionRightToLeft
  • Select Case Me.Alignment
  • Case Is = System.Windows.Forms.HorizontalAlignment.Left
  • Format.Alignment = System.Drawing.StringAlignment.Near
  • Case Is = System.Windows.Forms.HorizontalAlignment.Right
  • Format.Alignment = System.Drawing.StringAlignment.Far
  • Case Is = System.Windows.Forms.HorizontalAlignment.Center
  • Format.Alignment = System.Drawing.StringAlignment.Center
  • End Select
  • Format.FormatFlags = Format.FormatFlags Or System.Drawing.StringFormatFlags.NoWrap
  • g.FillRectangle(Brush:=BackBrush, Rect:=Rect)
  • Rect.Offset(0, MyClass._yMargin)
  • Rect.Height -= MyClass._yMargin
  • g.DrawString(Text, MyBase.DataGridTableStyle.DataGrid.Font, ForeBrush, RectF, Format)
  • Format.Dispose()
  • End Sub
  • #End Region
  • End Class
Public Class DataGridControlColumn
    Inherits System.Windows.Forms.DataGridColumnStyle

#Region "Variables"
    Private _xMargin As Integer = 2
    Private _yMargin As Integer = 1
    Private _Control As System.Windows.Forms.Control
    Private _OldVal As String = String.Empty
    Private _InEdit As Boolean = False
    Public InnerControlType As Type
    Public ColumnDataType As Type
    Public MinimumValuePropertyName As String
#End Region

#Region "Constructeurs"
    Public Sub New(ByVal TypeOfInnerControl As Type, ByVal MappingName As String, ByVal ColumnDataType As Type, ByVal Alignement As System.Windows.Forms.HorizontalAlignment, ByVal HeaderText As String, ByVal NullText As String, ByVal Width As Int32, Optional ByVal MinimumValuePropertyName As String = "")

        MyClass.New(TypeOfInnerControl, MappingName, ColumnDataType, MinimumValuePropertyName)
        MyBase.Alignment = Alignement
        MyBase.HeaderText = HeaderText
        MyBase.MappingName = MappingName
        MyBase.NullText = NullText
        MyBase.Width = Width
    End Sub

    Public Sub New(ByVal TypeOfInnerControl As Type, ByVal MappingName As String, ByVal ColumnDataType As Type, Optional ByVal MinimumValuePropertyName As String = "")

        MyClass.ColumnDataType = ColumnDataType
        MyClass.InnerControlType = TypeOfInnerControl
        MyBase.MappingName = MappingName
        MyClass._Control = Activator.CreateInstance(Me.InnerControlType)
        MyClass._Control.Visible = False
        MyClass.MinimumValuePropertyName = MinimumValuePropertyName

    End Sub

#End Region

    Public Property InnerControl() As System.Windows.Forms.Control
        Get
            Return MyClass._Control
        End Get
        Set(ByVal Value As System.Windows.Forms.Control)
            MyClass._Control = Value
        End Set
    End Property

#Region "Heritage de DataGridColumnStyle"
    Protected Overloads Overrides Sub Abort(ByVal RowNum As Integer)
        MyClass.RollBack()
        MyClass.HideForm()
        MyClass.EndEdit()
    End Sub

    Protected Overloads Overrides Function Commit(ByVal DataSource As System.Windows.Forms.CurrencyManager, ByVal RowNum As Integer) As Boolean
        Try
            MyClass.HideForm()
            If Not MyClass._InEdit Then Return True

            Dim Value As Object
            Dim Prop As Reflection.PropertyInfo = MyClass._Control.GetType.GetProperty("Value")
            If Prop Is Nothing Then
                Value = MyClass._Control.Text
            Else
                Value = Prop.GetValue(MyClass._Control, Nothing)
            End If

            If NullText.Equals(MyClass.GetText(Value)) Then
                Value = System.DBNull.Value
                MyBase.SetColumnValueAtRow(DataSource, RowNum, MyClass.NullText)
            Else
                Value = Convert.ChangeType(Value, MyClass.ColumnDataType)
                If Value.GetType Is MyClass.ColumnDataType Then
                    MyBase.SetColumnValueAtRow(DataSource, RowNum, Value)
                Else
                    Return False
                End If
            End If

        Catch e As Exception
            MyClass.RollBack()
            Return False
        End Try
        MyClass.EndEdit()
        Return True
    End Function

    Protected Overloads Overrides Sub ConcedeFocus()
        MyClass._Control.Visible = False
    End Sub

    Protected Overloads Overrides Sub Edit(ByVal Source As System.Windows.Forms.CurrencyManager, ByVal Rownum As Integer, ByVal Bounds As System.Drawing.Rectangle, ByVal [ReadOnly] As Boolean, ByVal InstantText As String, ByVal CellIsVisible As Boolean)

        If Not InstantText Is Nothing Then
            MyClass._Control.Text = InstantText
        Else            
            MyClass._Control.Text = MyClass.GetText(MyBase.GetColumnValueAtRow(Source, Rownum))
        End If

        Dim OriginalBounds As System.Drawing.Rectangle = Bounds

        MyClass._OldVal = MyClass._Control.Text

        If CellIsVisible Then
            Bounds.Offset(MyClass._xMargin, MyClass._yMargin)
            Bounds.Width -= MyClass._xMargin * 2
            Bounds.Height -= MyClass._yMargin
            MyClass._Control.Bounds = Bounds
            MyClass._Control.Visible = True
        Else
            MyClass._Control.Bounds = OriginalBounds
            MyClass._Control.Visible = False
        End If


        MyClass._Control.RightToLeft = MyBase.DataGridTableStyle.DataGrid.RightToLeft
        MyClass._Control.Focus()

        If MyClass._Control.Visible Then
            MyBase.DataGridTableStyle.DataGrid.Invalidate(OriginalBounds)
        End If

        MyClass._InEdit = True

    End Sub

#Region "Gestion des Tailles"
    Protected Overloads Overrides Function GetMinimumHeight() As Integer
        Return 25  'todo MyClass._Panel.PreferredHeight + MyClass._yMargin
    End Function

    Protected Overloads Overrides Function GetPreferredHeight(ByVal g As System.Drawing.Graphics, ByVal Value As Object) As Integer
        Dim NewLineIndex As Integer = 0
        Dim NewLines As Integer = 0
        Dim ValueString As String = MyClass.GetText(Value)
        Do
            While NewLineIndex <> -1
                NewLineIndex = ValueString.IndexOf("r\n", NewLineIndex + 1)
                NewLines += 1
            End While
        Loop

        Return MyBase.FontHeight * NewLines + MyClass._yMargin
    End Function

    Protected Overloads Overrides Function GetPreferredSize(ByVal g As System.Drawing.Graphics, ByVal Value As Object) As System.Drawing.Size
        Dim Extents As System.Drawing.Size = System.Drawing.Size.Ceiling(g.MeasureString(MyClass.GetText(Value), MyBase.DataGridTableStyle.DataGrid.Font))
        Extents.Width += MyClass._xMargin * 2 + MyClass.DataGridTableGridLineWidth
        Extents.Height += MyClass._yMargin
        Return Extents
    End Function
#End Region

#Region "Méthodes Paint"
    Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing.Graphics, ByVal Bounds As System.Drawing.Rectangle, ByVal Source As System.Windows.Forms.CurrencyManager, ByVal RowNum As Integer)
        MyClass.Paint(g, Bounds, Source, RowNum, False)
    End Sub

    Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing.Graphics, ByVal Bounds As System.Drawing.Rectangle, ByVal Source As System.Windows.Forms.CurrencyManager, ByVal RowNum As Integer, ByVal AlignToRight As Boolean)
        Dim Text As String = MyClass.GetText(MyBase.GetColumnValueAtRow(Source, RowNum))
        MyClass.PaintText(g, Bounds, Text, AlignToRight)
    End Sub

    Protected Overloads Sub Paint(ByVal g As System.Drawing.Graphics, ByVal Bounds As System.Drawing.Rectangle, ByVal Source As System.Windows.Forms.CurrencyManager, ByVal RowNum As Integer, ByVal BackBrush As System.Drawing.Brush, ByVal ForeBrush As System.Drawing.Brush, ByVal AlignToRight As Boolean)

        Dim Text As String = MyClass.GetText(MyBase.GetColumnValueAtRow(Source, RowNum))
        MyClass.PaintText(g, Bounds, Text, BackBrush, ForeBrush, AlignToRight)
    End Sub
#End Region

    Protected Overloads Overrides Sub SetDataGridInColumn(ByVal Value As System.Windows.Forms.DataGrid)
        MyBase.SetDataGridInColumn(Value)
        If Not (MyClass._Control.Parent Is Value) Then
            If Not (MyClass._Control.Parent Is Nothing) Then
                MyClass._Control.Parent.Controls.Remove(MyClass._Control)
            End If
        End If

        If Not (Value Is Nothing) Then
            'MyClass._Control.Owner = Value.FindForm
            Value.Controls.Add(MyClass._Control)
        End If
    End Sub

    Protected Overloads Overrides Sub UpdateUI(ByVal Source As System.Windows.Forms.CurrencyManager, ByVal RowNum As Integer, ByVal InstantText As String)
        MyClass._Control.Text = MyClass.GetText(MyBase.GetColumnValueAtRow(Source, RowNum))
        If Not (InstantText Is Nothing) Then
            MyClass._Control.Text = InstantText
        End If
    End Sub
#End Region

#Region "Méthodes privées"
    Private ReadOnly Property DataGridTableGridLineWidth() As Integer
        Get
            If MyBase.DataGridTableStyle.GridLineStyle = System.Windows.Forms.DataGridLineStyle.Solid Then
                Return 1
            Else
                Return 0
            End If
        End Get
    End Property
    Private Sub EndEdit()
        MyClass._InEdit = False
        MyBase.Invalidate()
    End Sub

    Private Function GetText(ByVal Value As Object) As String

        If MyClass.MinimumValuePropertyName <> String.Empty Then
            Dim Prop As Reflection.PropertyInfo = MyClass._Control.GetType.GetProperty(MyClass.MinimumValuePropertyName)
            If Not Prop Is Nothing Then
                Dim Obj As Object = Convert.ChangeType(Prop.GetValue(MyClass._Control, Nothing), MyClass.ColumnDataType)
                If Value.compareto(Obj) < 0 Then Value = Obj            
            End If
        End If

        If Value Is System.DBNull.Value Then Return NullText

        If Not Value Is Nothing Then
            Return Value.ToString
        Else
            Return NullText
        End If

    End Function

    Private Sub HideForm()
        If MyClass._Control.Focused Then
            MyBase.DataGridTableStyle.DataGrid.Focus()
        End If
        MyClass._Control.Visible = False

    End Sub

    Private Sub RollBack()
        MyClass._Control.Text = MyClass._OldVal
    End Sub

    Private Sub PaintText(ByVal g As System.Drawing.Graphics, ByVal Bounds As System.Drawing.Rectangle, ByVal Text As String, ByVal AlignToRight As Boolean)

        Dim BackBrush As System.Drawing.Brush = New System.Drawing.SolidBrush(MyBase.DataGridTableStyle.BackColor)
        Dim ForeBrush As System.Drawing.Brush = New System.Drawing.SolidBrush(MyBase.DataGridTableStyle.ForeColor)
        MyClass.PaintText(g, Bounds, Text, BackBrush, ForeBrush, AlignToRight)
    End Sub

    Private Sub PaintText(ByVal g As System.Drawing.Graphics, ByVal TextBounds As System.Drawing.Rectangle, ByVal Text As String, ByVal BackBrush As System.Drawing.Brush, ByVal ForeBrush As System.Drawing.Brush, ByVal AlignToRight As Boolean)

        Dim Rect As System.Drawing.Rectangle = TextBounds
        Dim RectF As System.Drawing.RectangleF = System.Drawing.RectangleF.op_Implicit(Rect) ' Convert to RectangleF
        Dim Format As System.Drawing.StringFormat = New System.Drawing.StringFormat()

        If AlignToRight Then Format.FormatFlags = System.Drawing.StringFormatFlags.DirectionRightToLeft

        Select Case Me.Alignment
            Case Is = System.Windows.Forms.HorizontalAlignment.Left
                Format.Alignment = System.Drawing.StringAlignment.Near
            Case Is = System.Windows.Forms.HorizontalAlignment.Right
                Format.Alignment = System.Drawing.StringAlignment.Far
            Case Is = System.Windows.Forms.HorizontalAlignment.Center
                Format.Alignment = System.Drawing.StringAlignment.Center
        End Select

        Format.FormatFlags = Format.FormatFlags Or System.Drawing.StringFormatFlags.NoWrap
        g.FillRectangle(Brush:=BackBrush, Rect:=Rect)

        Rect.Offset(0, MyClass._yMargin)
        Rect.Height -= MyClass._yMargin
        g.DrawString(Text, MyBase.DataGridTableStyle.DataGrid.Font, ForeBrush, RectF, Format)
        Format.Dispose()

    End Sub
#End Region
End Class

 Conclusion

Ce code est basé sur l'exemple de Microsoft (comme le code de strikel).

Code Modifié: Correction de la gestion de la saisie. Ajout de la possibilité de choisir le type de données avec lequel travailler. Passage de valeur par la propriété Text ou Value. Value étant prioritaire, Correction et Amélioration de la gestion des valeurs Null.

Ajout d'un zip contenant un exemple de Datagrid avec TextBox, DataTimePicker et UserControl sur un Databinding avec une collection Typée.

Pas de commentaire pour le moment (pas eu le temps)

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Sources du même auteur

Source avec Zip Source avec une capture Source .NET (Dotnet) ANGLECONTROL WITH DESIGNTIME CODE (CONTROLDESIGNER, UITYPEED...
Source avec Zip Source .NET (Dotnet) DÉPLACER UN FORMULAIRE SANS BARRE DE TITRE

 Sources de la même categorie

Source .NET (Dotnet) MODIFICATION DATE DE WINDOWS EN VB.NET ET VBA par us_30
Source avec Zip Source avec une capture Source .NET (Dotnet) ENVOI DE MAIL AVEC PIÈCE JOINTE par EhJoe
Source .NET (Dotnet) AMUSONS NOUS AVEC UN LABEL ^^ par Adn56
Source avec Zip Source avec une capture Source .NET (Dotnet) UN NAVIGATEUR INTERNET EN VB.NET par azrti
Source avec Zip Source .NET (Dotnet) CONVERSION DE DEVISE MONAITAIRE VIA UN SERVICE WEB par bigmonkey7

Commentaires et avis

Commentaire de labout le 09/12/2003 11:16:01

Peux-tu donner quelques explications sur l'utilisation de cette DLL ou mieux fournir un petit exemple car là on ne voit pas la fonctionnalité.
Merci

Commentaire de labout le 09/12/2003 12:06:12

Lors de la création de la DLL j'ai le message
Le concepteur doit créer une instance de type 'System.Windows.Form.DataGridColumnStyle' mais il ne peut pas car le type est déclaré comme abstract.
Que faire pour corriger cette erreur.
Je précise que je suis en .NET 2003
Merci de tes lumières.

Commentaire de CeTjsMoi le 09/12/2003 15:11:54

Vérifie si ta dll référence bien system.windows.forms. (par défaut ce n'est pas le cas pour une dll.)

Je vais mettre en ligne les sources d'un exemple dès cet après-midi.

Commentaire de labout le 10/12/2003 10:14:25

J'ai bien fait ce qu'il faut mais c'est pareil.
J'attends ton exemple
Merci

Commentaire de CeTjsMoi le 10/12/2003 11:20:07

l'exemple est déjà là, il suffit de télécharger le zip avec les sources

Commentaire de CeTjsMoi le 10/12/2003 12:20:59

Ca fait plaisir la note de 1/10,
le même code avec juste un label était noté 8/10.

Commentaire de labout le 10/12/2003 12:35:49

Le code ne marche pas, erreur à la compil cité plus haut et aucune documentation. Bien sur je reviserai mon jugement lorsque j'aurai pu faire quelque chose avec mais le zip joint est illisible message d'errerus à l'ouverture. Vérifie par toi-même.

Commentaire de CeTjsMoi le 10/12/2003 15:35:14

En effet le zip ne fonctionnait pas. C'est bizarre, je l'ai téléchargé hier soir de chez moi et il fonctionnait.
J'ai remis en ligne le source avec l'exemple (sans les exe cette fois).

Quand a l'erreur dont tu parlais, elle a été corrigée hier, il faut que tu recopie a nouveau la class pour que ca marche (Le mode édition ne fonctionnait plus)

Désolé pour le retard et pour les erreurs, j'avais pas fait attention.

Tout devrait fonctionner maintenant.

Commentaire de labout le 10/12/2003 16:35:34

J'ai toujours le message d'erreur sur la class mais cela ne l'empêche pas de fonctionner encore une bizarerie de Bill.
C'est effectivement très bien et j'ai comme promis modifié ma note 9.
Je te remercie et désolé de t'avoir ennuyé autant.

Commentaire de sahmark le 10/12/2003 18:14:09

Voici le message qui apparaît au lancement du programme

Le fichier selectionné n'est pas valable dans Visual Studio
Que faire dans ce cas pour l'exécuter

Commentaire de CeTjsMoi le 11/12/2003 16:56:10

Plutôt bizarre comme message. C'est sur quel fichier?

Commentaire de labout le 11/12/2003 18:15:53

Chez moi cela marche parfaitement.
Je suis en version 2003, le Pb pour Sahmark vient peut-etre de là.
Désolé il ne veut pas que je change ma note mais je te mets 10/10
ici pour ceux qui liront jusqu'au bout.
Salut

Commentaire de CeTjsMoi le 12/12/2003 10:41:00

Shalmark&gt; si tu est en .net 2002, il faut que tu refasses toi même les fichiers de solutions (les fichiers de solutions 2003 ne sont pas compatibles avec les fichiers solutions 2002) et peut-être aussi les fichiers de projets; par contre les autres fichiers sont compatibles.

Commentaire de Spoon-BE le 28/12/2003 16:22:39

Bonjour,
Cet exemple est très intéressant, mais j'ai un problème lors de la navigation dans la grille avec la touche Tab. Si on utilise Tab ou Shift Tab le curseur se déplace de 2 cellules. Comment est-il possible de résoudre ce problème? Merci d'avance.
Spoon-BE

Commentaire de lelulufou le 22/01/2004 14:02:28

Bonjour, cela marche pas trop mal, mais lorsque la datagrid est liée à une table d'une db il y a une erreur si on veux ajouter une ligne. Comment résoudre le problème ? merci d'avance

Commentaire de olixelle le 22/08/2004 21:18:41

C'est du bon travail....

Commentaire de PierrotVB le 20/10/2004 00:38:45

malin de passer le type

Commentaire de x chatard le 02/03/2005 17:01:52

Je travaille justement sur ca, bon travail mais je remarque que comme pour moi la gestion des tabulations reste un grand mystere. Perso je n'en ai besoin que pour un combobox en dropdown et ca me rend fou ! ! ! Si quelqu'un a une solution ? ? ?

Commentaire de adeath le 27/07/2005 09:52:41

Vraiment super ta source.
Par contre avec cette classe, le datagrid ne réagit pas avec la méthode Select()  (Sélection d'une ligne).

Commentaire de pinje le 29/11/2005 15:13:21

Bonjour a tous,

merci CeTjsMoi pour cette source. J'utilise le meme genre de classe pour mettre une combobox dans un datagrid, mais je suis confronte a la difficulte suivante: comment fais tu dans ta form frmTest pour recuperer les evenements du ComboBox que tu as ajouter dans le datagrid?? merci

 Ajouter un commentaire




Nos sponsors


Sondage...

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

Photothèque

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 1,638 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales