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

Windows Forms Discussion :

[C#] - Databinding numericUpDow avec tabulation


Sujet :

Windows Forms

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2006
    Messages
    72
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Septembre 2006
    Messages : 72
    Par défaut [C#] - Databinding numericUpDow avec tabulation
    Bonjour,

    Sur un formulaire j'ai plusieurs numericUpDown qui sont bindés sur des proprités d'un objet.
    Mon problème est que lorsque je modifie la valeur du numéricUpDown (manuellement ou avec les boutons) et que je quitte le contrôle avec une tabulation la valeur de la propriété de mon objet n'est pas mise à jour.

    Si je quitte le contrôle en cliquant sur un autre ou que j'appuie sur "Enter" avant de faire une tabulation ça fonctionne.

    Est-ce que quelqu'un sait comment résoudre ça ?

    Merci d'avance.

  2. #2
    Rédacteur
    Avatar de Thomas Lebrun
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    9 161
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Par défaut
    Il faut que ton objet implémente l'interface INotifyPropertyChanged: http://msdn2.microsoft.com/en-us/library/ms229614.aspx

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2006
    Messages
    72
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Septembre 2006
    Messages : 72
    Par défaut
    Merci mais en fait mon problème concerne la synchronisation dans l'autre sens.

    Lorsque je change la valeur de la propriété de mon objet dans le code, il "informe" bien mon contrôle qui se met à jour.

    Par contre, si je saisie une valeur dans mon numericUpDown et je j'appuie sur Tab, ça ne modifie pas la valeur de la propriété de mon object (en mode debug, je ne passe pas dans le code de la propriété).
    Si je saisie une valeur et que je clique sur le contrôle suivant, la valeur de la propriété est modifiée.

    Une idée ?

  4. #4
    Membre confirmé
    Développeur informatique
    Inscrit en
    Mars 2005
    Messages
    110
    Détails du profil
    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mars 2005
    Messages : 110
    Par défaut
    Salut,
    cela aide-t-il de changer le data source update mode du contrôle à OnPropertyChanged ou lieu de OnValidation (qu est le defaut)?
    Bonsoir
    Dom

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2006
    Messages
    72
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Septembre 2006
    Messages : 72
    Par défaut
    Merci pour l'idée, je viens d'essayer et ça ne marche pas non plus

  6. #6
    Membre confirmé
    Développeur informatique
    Inscrit en
    Mars 2005
    Messages
    110
    Détails du profil
    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mars 2005
    Messages : 110
    Par défaut
    Salut,
    Ca m'a rendu curieux du coup je viens d'essayer.
    Avec le mode d'update de la source à OnPropertyChanged tout marche bien
    Avec le mode d'update de la source à OnValidation le comportement est en effet déroutant. Dans certaines circonstances la tabulation marche et dans d'autres non.
    la classe "métier":
    Code vb : 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
    Option Explicit On
    Option Strict On
    Imports System.ComponentModel
    Public Class Form1
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.BindingSource1.DataSource = New DummyModel()
        End Sub
    End Class
     
    Public Class DummyModel
        Implements INotifyPropertyChanged
     
        Private mCounter As Int32 = 0
     
        Public Property Counter() As Int32
            Get
                Return mCounter
            End Get
            Set(ByVal value As Int32)
                System.Diagnostics.Debug.Print("Enter Counter setter with value: " & value.ToString())
                If mCounter <> value Then
                    mCounter = value
                    RaisePropertyChanged("Counter")
                End If
            End Set
        End Property
     
        Public Overrides Function ToString() As String
            Return String.Format("Value is {0}", mCounter)
        End Function
     
        Private Sub RaisePropertyChanged(ByVal info As String)
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
        End Sub
     
        Public Event PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
    End Class
    Ca sent le bug tout ca

    bon courage...
    Dom
    ps: le code généré par le designer si ca t'intéresse:
    Code vb : 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
    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    Partial Class Form1
        Inherits System.Windows.Forms.Form
     
        'Form overrides dispose to clean up the component list.
        <System.Diagnostics.DebuggerNonUserCode()> _
        Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            Try
                If disposing AndAlso components IsNot Nothing Then
                    components.Dispose()
                End If
            Finally
                MyBase.Dispose(disposing)
            End Try
        End Sub
     
        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer
     
        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        <System.Diagnostics.DebuggerStepThrough()> _
        Private Sub InitializeComponent()
            Me.components = New System.ComponentModel.Container
            Me.Label1 = New System.Windows.Forms.Label
            Me.TextBox1 = New System.Windows.Forms.TextBox
            Me.NumericUpDown1 = New System.Windows.Forms.NumericUpDown
            Me.TextBox2 = New System.Windows.Forms.TextBox
            Me.Label2 = New System.Windows.Forms.Label
            Me.ErrorProvider1 = New System.Windows.Forms.ErrorProvider(Me.components)
            Me.BindingSource1 = New System.Windows.Forms.BindingSource(Me.components)
            CType(Me.NumericUpDown1, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.ErrorProvider1, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.BindingSource1, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.SuspendLayout()
            '
            'Label1
            '
            Me.Label1.AutoSize = True
            Me.Label1.Location = New System.Drawing.Point(64, 94)
            Me.Label1.Name = "Label1"
            Me.Label1.Size = New System.Drawing.Size(69, 13)
            Me.Label1.TabIndex = 0
            Me.Label1.Text = "Control value"
            '
            'TextBox1
            '
            Me.TextBox1.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource1, "Counter", True, System.Windows.Forms.DataSourceUpdateMode.OnValidation, Nothing, "N0"))
            Me.TextBox1.Location = New System.Drawing.Point(149, 87)
            Me.TextBox1.Name = "TextBox1"
            Me.TextBox1.Size = New System.Drawing.Size(100, 20)
            Me.TextBox1.TabIndex = 2
            '
            'NumericUpDown1
            '
    ' avec onpropertychanged:
    ' Me.NumericUpDown1.DataBindings.Add(New System.Windows.Forms.Binding("Value", Me.BindingSource1, "Counter", True, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged))
            Me.NumericUpDown1.DataBindings.Add(New System.Windows.Forms.Binding("Value", Me.BindingSource1, "Counter", True))
            Me.NumericUpDown1.Location = New System.Drawing.Point(129, 12)
            Me.NumericUpDown1.Name = "NumericUpDown1"
            Me.NumericUpDown1.Size = New System.Drawing.Size(120, 20)
            Me.NumericUpDown1.TabIndex = 0
            '
            'TextBox2
            '
            Me.TextBox2.Location = New System.Drawing.Point(149, 49)
            Me.TextBox2.Name = "TextBox2"
            Me.TextBox2.Size = New System.Drawing.Size(100, 20)
            Me.TextBox2.TabIndex = 1
            '
            'Label2
            '
            Me.Label2.AutoSize = True
            Me.Label2.Location = New System.Drawing.Point(17, 56)
            Me.Label2.Name = "Label2"
            Me.Label2.Size = New System.Drawing.Size(126, 13)
            Me.Label2.TabIndex = 4
            Me.Label2.Text = "Dummy label (not boiund)"
            '
            'ErrorProvider1
            '
            Me.ErrorProvider1.ContainerControl = Me
            Me.ErrorProvider1.DataSource = Me.BindingSource1
            '
            'BindingSource1
            '
            Me.BindingSource1.DataSource = GetType(NumericUpDownTest.DummyModel)
            '
            'Form1
            '
            Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
            Me.ClientSize = New System.Drawing.Size(273, 137)
            Me.Controls.Add(Me.Label2)
            Me.Controls.Add(Me.TextBox2)
            Me.Controls.Add(Me.NumericUpDown1)
            Me.Controls.Add(Me.TextBox1)
            Me.Controls.Add(Me.Label1)
            Me.Name = "Form1"
            Me.Text = "Form1"
            CType(Me.NumericUpDown1, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.ErrorProvider1, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.BindingSource1, System.ComponentModel.ISupportInitialize).EndInit()
            Me.ResumeLayout(False)
            Me.PerformLayout()
     
        End Sub
        Friend WithEvents Label1 As System.Windows.Forms.Label
        Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
        Friend WithEvents NumericUpDown1 As System.Windows.Forms.NumericUpDown
        Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
        Friend WithEvents Label2 As System.Windows.Forms.Label
        Friend WithEvents BindingSource1 As System.Windows.Forms.BindingSource
        Friend WithEvents ErrorProvider1 As System.Windows.Forms.ErrorProvider
     
    End Class

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

Discussions similaires

  1. [XSD] [DataBinding] XML avec de l'héritage
    Par PoteA_Tooz dans le forum Format d'échange (XML, JSON...)
    Réponses: 1
    Dernier message: 25/04/2008, 12h54
  2. [Tableaux] Explode avec tabulations
    Par Caponord38 dans le forum Langage
    Réponses: 3
    Dernier message: 07/03/2008, 22h15
  3. Réponses: 7
    Dernier message: 14/12/2007, 09h02
  4. [Tableaux] récupérer un texte avec tabulations
    Par pclover dans le forum Langage
    Réponses: 3
    Dernier message: 09/02/2007, 14h07
  5. [Vb.Net]NumericUpDown et DataBinding : problème avec la valeur min
    Par SamRay1024 dans le forum Windows Forms
    Réponses: 3
    Dernier message: 25/04/2006, 16h34

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