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 :

Ne rien mettre dans un DateTimePicker


Sujet :

VB.NET

  1. #1
    Membre actif Avatar de Elwe31
    Profil pro
    Inscrit en
    Octobre 2004
    Messages
    487
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Octobre 2004
    Messages : 487
    Points : 220
    Points
    220
    Par défaut Ne rien mettre dans un DateTimePicker
    Bonjour,

    Est-il possible de mettre "rien"(qu'il ne s'affiche aucune date) dans un datetimepicker ???
    J'ai essayer ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Me.DateTimeDebut.Text = ""
    ou encore
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Me.DateTimeDebut = nothing
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Me.DateTimeDebut = dbnull.value
    Quelqu'un a une idée ???
    j'ai trouvé ça : http://www.developpez.net/forums/showthread.php?t=91674
    mais je ne sais pas comment je peux(et meme si cela est possible) le traduir en vb.net !

    merci d'avance

  2. #2
    Membre actif Avatar de Elwe31
    Profil pro
    Inscrit en
    Octobre 2004
    Messages
    487
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Octobre 2004
    Messages : 487
    Points : 220
    Points
    220
    Par défaut
    J'ai trouvé ça aussi....
    mais toujours rien en vb.net !!!!!!
    http://rickchoi.blogspot.com/2006/02...imepicker.html

  3. #3
    Membre actif Avatar de Elwe31
    Profil pro
    Inscrit en
    Octobre 2004
    Messages
    487
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Octobre 2004
    Messages : 487
    Points : 220
    Points
    220
    Par défaut
    Ben alors !!! Personne

    En fait, j'ai trouvé :
    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
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
     
    Imports System
    Imports System.ComponentModel
    Imports System.Globalization
    Imports System.Runtime.InteropServices
    Imports System.Threading
    Imports System.Windows.Forms
    Namespace outils
        ''' <summary>
        ''' Represents a Windows date time picker control. It enhances the .NET standard <b>DateTimePicker</b>
        ''' control with a ReadOnly mode as well as with the possibility to show empty values (null values).
        ''' </summary>
        <ComVisible(False)> _
        Public Class NullableDateTimePicker
            Inherits System.Windows.Forms.DateTimePicker
    #Region "Member variables"
            ' true, when no date shall be displayed (empty DateTimePicker)
            Private _isNull As Boolean
     
            ' If _isNull = true, this value is shown in the DTP
            Private _nullValue As String
     
            ' The format of the DateTimePicker control
            Private _format As DateTimePickerFormat = DateTimePickerFormat.[Long]
     
            ' The custom format of the DateTimePicker control
            Private _customFormat As String
     
            ' The format of the DateTimePicker control as string
            Private _formatAsString As String
    #End Region
     
    #Region "Constructor"
            ''' <summary>
            ''' Default Constructor
            ''' </summary>
            Public Sub New()
                MyBase.New()
                MyBase.Format = DateTimePickerFormat.[Custom]
                NullValue = " "
                Format = DateTimePickerFormat.[Long]
            End Sub
    #End Region
     
    #Region "Public properties"
     
            ''' <summary>
            ''' Gets or sets the date/time value assigned to the control.
            ''' </summary>
            ''' <value>The DateTime value assigned to the control
            ''' </value>
            ''' <remarks>
            ''' <p>If the <b>Value</b> property has not been changed in code or by the user, it is set
            ''' to the current date and time (<see cref="DateTime.Now"/>).</p>
            ''' <p>If <b>Value</b> is <b>null</b>, the DateTimePicker shows 
            ''' <see cref="NullValue"/>.</p>
            ''' </remarks>
            Public Overloads Property Value() As Object
                Get
                    If _isNull Then
                        Return Nothing
                    Else
                        Return MyBase.Value
                    End If
                End Get
                Set(ByVal value As Object)
                    If value Is Nothing OrElse value = "" Then
                        SetToNullValue()
                    Else
                        SetToDateTimeValue()
                        MyBase.Value = DirectCast(value, DateTime)
                    End If
                End Set
            End Property
     
            ''' <summary>
            ''' Gets or sets the format of the date and time displayed in the control.
            ''' </summary>
            ''' <value>One of the <see cref="DateTimePickerFormat"/> values. The default is 
            ''' <see cref="DateTimePickerFormat.Long"/>.</value>
            <Browsable(True), _
             DefaultValue(DateTimePickerFormat.[Long]), TypeConverter(GetType([Enum]))> _
            Public Shadows Property Format() As DateTimePickerFormat
                Get
                    Return _format
                End Get
                Set(ByVal value As DateTimePickerFormat)
                    _format = value
                    SetFormat()
                    OnFormatChanged(EventArgs.Empty)
                End Set
            End Property
     
            ''' <summary>
            ''' Gets or sets the custom date/time format string.
            ''' <value>A string that represents the custom date/time format. The default is a null
            ''' reference (<b>Nothing</b> in Visual Basic).</value>
            ''' </summary>
            Public Shadows Property CustomFormat() As String
                Get
                    Return _customFormat
                End Get
                Set(ByVal value As String)
                    _customFormat = value
                End Set
            End Property
     
            ''' <summary>
            ''' Gets or sets the string value that is assigned to the control as null value. 
            ''' </summary>
            ''' <value>The string value assigned to the control as null value.</value>
            ''' <remarks>
            ''' If the <see cref="Value"/> is <b>null</b>, <b>NullValue</b> is
            ''' shown in the <b>DateTimePicker</b> control.
            ''' </remarks>
            <Browsable(True), _
             Category("Behavior"), _
             Description("The string used to display null values in the control"), _
             DefaultValue(" ")> _
            Public Property NullValue() As String
                Get
                    Return _nullValue
                End Get
                Set(ByVal value As String)
                    _nullValue = value
                End Set
            End Property
    #End Region
     
    #Region "Private methods/properties"
            ''' <summary>
            ''' Stores the current format of the DateTimePicker as string. 
            ''' </summary>
            Private Property FormatAsString() As String
                Get
                    Return _formatAsString
                End Get
                Set(ByVal value As String)
                    _formatAsString = value
                    MyBase.CustomFormat = value
                End Set
            End Property
     
            ''' <summary>
            ''' Sets the format according to the current DateTimePickerFormat.
            ''' </summary>
            Private Sub SetFormat()
                Dim ci As CultureInfo = Thread.CurrentThread.CurrentCulture
                Dim dtf As DateTimeFormatInfo = ci.DateTimeFormat
                Select Case _format
                    Case DateTimePickerFormat.[Long]
                        FormatAsString = dtf.LongDatePattern
                    Case DateTimePickerFormat.[Short]
                        FormatAsString = dtf.ShortDatePattern
                    Case DateTimePickerFormat.Time
                        FormatAsString = dtf.ShortTimePattern
                    Case DateTimePickerFormat.[Custom]
                        FormatAsString = Me.CustomFormat
                End Select
            End Sub
     
            ''' <summary>
            ''' Sets the <b>DateTimePicker</b> to the value of the <see cref="NullValue"/> property.
            ''' </summary>
            Private Sub SetToNullValue()
                _isNull = True
                MyBase.CustomFormat = IIf((_nullValue = Nothing OrElse _nullValue = [String].Empty), " ", "'" + _nullValue + "'")
            End Sub
     
            ''' <summary>
            ''' Sets the <b>DateTimePicker</b> back to a non null value.
            ''' </summary>
            Private Sub SetToDateTimeValue()
                If _isNull Then
                    SetFormat()
                    _isNull = False
                    MyBase.OnValueChanged(New EventArgs())
                End If
            End Sub
    #End Region
     
    #Region "OnXXXX()"
     
            ''' <summary>
            ''' This member overrides <see cref="DateTimePicker.OnCloseUp"/>.
            ''' </summary>
            ''' <param name="e"></param>
            Protected Overloads Overrides Sub OnCloseUp(ByVal e As EventArgs)
                If Control.MouseButtons = Windows.Forms.MouseButtons.None Then
                    If _isNull Then
                        SetToDateTimeValue()
                        _isNull = False
                    End If
                End If
                MyBase.OnCloseUp(e)
            End Sub
     
     
            ''' <summary>
            ''' This member overrides <see cref="Control.OnKeyDown"/>.
            ''' </summary>
            ''' <param name="e"></param>
            Protected Overloads Overrides Sub OnKeyUp(ByVal e As KeyEventArgs)
                If e.KeyCode = Keys.Delete Then
                    Me.Value = Nothing
                    OnValueChanged(EventArgs.Empty)
                End If
                MyBase.OnKeyUp(e)
            End Sub
    #End Region
     
            Private Sub InitializeComponent()
     
            End Sub
        End Class
    End Namespace
    Je remplace tout mes Datatimepicker par des NullableDateTimePicker
    et ça marche du feux de dieux !!!

  4. #4
    Expert éminent sénior Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 175
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 175
    Points : 25 116
    Points
    25 116
    Par défaut
    j'ajoute qu'il n'est pas possible de mettre rien dans une value as date car date est un type par valeur et non un type objet qui comprend un pointeur

  5. #5
    Membre actif Avatar de Elwe31
    Profil pro
    Inscrit en
    Octobre 2004
    Messages
    487
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Octobre 2004
    Messages : 487
    Points : 220
    Points
    220
    Par défaut
    Bon, ben, non ça fonctionne pas terrible!!!!

    Si je fais :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Me.DateTimeDebut.Value = nothing
    je ne peux plus rien mettre comme valeur dans le champs, ni par code ni en selectionnant une valeur dans la liste.

    Par contre, si j'appuis sur la touche "supp" quand je suis dans le champs, ça fonctionne tres bien !!!

    quelqu'un a une petite idée ?????

  6. #6
    Membre actif Avatar de Elwe31
    Profil pro
    Inscrit en
    Octobre 2004
    Messages
    487
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Octobre 2004
    Messages : 487
    Points : 220
    Points
    220
    Par défaut
    Quelqu'un peut-il aussi me dire :
    Pourquoi l'evenement DateTimePicker_ValueChanged une fois teerminé, appel l'evenement form_Activated ???

    merci

  7. #7
    Rédacteur
    Avatar de SaumonAgile
    Homme Profil pro
    Team leader
    Inscrit en
    Avril 2007
    Messages
    4 028
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Team leader
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2007
    Messages : 4 028
    Points : 6 334
    Points
    6 334
    Par défaut
    Pourquoi vouloir mettre null dans un champ de saisie date, ça n'a pas de sens à mon avis...
    Pour ce genre de situation, j'utilise la possibilité d'afficher un checkbox dans le datetimepicker, et ensuite, si le checkbox est coché, j'utilise la date contenue dans le dtp, et si elle n'est pas cochée, je ne l'utilise pas.
    Tu peux associer ce comportement avec l'utilisation d'un objet DateTime nullable, plutot qu'un datetime simple.

  8. #8
    Membre actif Avatar de Elwe31
    Profil pro
    Inscrit en
    Octobre 2004
    Messages
    487
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Octobre 2004
    Messages : 487
    Points : 220
    Points
    220
    Par défaut
    Ok,

    Mais comment peux-tu faire pour ne pas afficher de date quand il n'y en a pas !!! (dans un champs d'une base de données par exemple)

    J'ai pensé et testé(oui, oui, ça m'arrive )
    Mettre un textbox a coté du datetimepicker(ou je fais apparaitre juste la petite fleche pour faire apparaitre la liste de choix)
    et sur l'evenement DateTimePicker_ValueChanged, je mets a jour le textbox...
    ça fonctionne nickel(meme si je n'ai pas tres joli)
    sauf que comme je fais un init de tous les champs dans l'evenement form_Activated
    et que le DateTimePicker_ValueChanged appel form_Activated et ben c'est mort !

  9. #9
    Rédacteur
    Avatar de SaumonAgile
    Homme Profil pro
    Team leader
    Inscrit en
    Avril 2007
    Messages
    4 028
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Team leader
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2007
    Messages : 4 028
    Points : 6 334
    Points
    6 334
    Par défaut
    S'il y a une date, tu coches le checkbox du dtp, sinon tu ne le coches pas.

  10. #10
    Membre actif Avatar de Elwe31
    Profil pro
    Inscrit en
    Octobre 2004
    Messages
    487
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Octobre 2004
    Messages : 487
    Points : 220
    Points
    220
    Par défaut
    Ok, cool, j'avais pas vu le checkbox....super,

    par contre ça change rien, l'evenement DateTimePicker_ValueChanged appel form_Activated.

    merci

  11. #11
    Membre actif
    Inscrit en
    Avril 2006
    Messages
    346
    Détails du profil
    Informations forums :
    Inscription : Avril 2006
    Messages : 346
    Points : 252
    Points
    252
    Par défaut
    Bonjour,

    tu peux utiliser le lien que tu as trouvé.
    Pour le traduire en vb.net, tu peux regarder ce lien:

    http://labs.developerfusion.co.uk/co...arp-to-vb.aspx

    A bientôt
    Nicolas

  12. #12
    Expert éminent sénior Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 175
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 175
    Points : 25 116
    Points
    25 116
    Par défaut
    form activated est à priori executé à chaque fois que l'appli reprend la main sur cette fenetre

    si tu dois initialiser quelque chose c'est dans le sub new, ca sert à ca !!
    (ou encore form loaded)

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Je ne sais plus rien mettre dans la corbeille !
    Par Papy Octet dans le forum Applications et environnements graphiques
    Réponses: 1
    Dernier message: 24/09/2009, 19h28
  2. [ACCESS] Comment ne rien mettre dans un champs date ??
    Par Dryss51 dans le forum Requêtes et SQL.
    Réponses: 2
    Dernier message: 07/08/2007, 16h11
  3. Réponses: 8
    Dernier message: 26/08/2004, 18h59
  4. piece jointe à mettre dans outlook
    Par Tierisa dans le forum VBA Access
    Réponses: 52
    Dernier message: 21/10/2003, 15h32
  5. [langage] Problème de taille de fichier à mettre dans
    Par And_the_problem_is dans le forum Langage
    Réponses: 10
    Dernier message: 13/08/2002, 09h41

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