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#] Gestion des cellules d'une DataGridViewComboBoxColumn séparement


Sujet :

Windows Forms

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2010
    Messages
    31
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2010
    Messages : 31
    Points : 29
    Points
    29
    Par défaut [C#] Gestion des cellules d'une DataGridViewComboBoxColumn séparement
    Bonjour à tous

    Je cherche à gérer les cellules d'une DataGridViewComboBoxColumn separement:

    Je crée un datagridview en créant manuellement toutes les colonnes et je les ajoute selon une table de paramétrage.

    dedans, j'ai une colonne avec des comboboxs et je souhaiterais ajouter a chaque ligne des valeurs différentes.

    exemple: la combo de la ligne une propose : 1,2,3

    la combo de la ligne 2 propose : 4,5,6

    ......

    Si quelqu'un peux me dire s'il est possible de le faire ou comment faire pour que ce soit transparent pour l'utilisateur?

    merci bcp à tous et bonne journée

    Tom

  2. #2
    Expert éminent Avatar de Graffito
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    5 993
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 5 993
    Points : 7 903
    Points
    7 903
    Par défaut
    Bonjour,

    On doit y arriver en changeant la propriété DataSource de la DataGridViewComboBoxColumn sur l'événement CellEnter du DataGridView.

    Dans ton exemple, on aurait 2 DataSource : une avec {1,2,3}, l'autre avec {4,5,6}.

    Une autre possibilté consisterait (toujours sur l'event CellEnter) à reconstruire dynamiquement la DataSource. Mais, il me semble que pour "valider" la modification du DataSource, il faut mettre cette propriété à null, puis la réaffecter.
    " Le croquemitaine ! Aaaaaah ! Où ça ? " ©Homer Simpson

  3. #3
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2010
    Messages
    31
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2010
    Messages : 31
    Points : 29
    Points
    29
    Par défaut
    Lorsque je modifie le datasource il me renvoi l'erreur ci dessous
    voici mon code:
    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
    private void traction_click(object sender, EventArgs e)
            {
                if (((System.Windows.Forms.DataGridView)(sender)).CurrentCell.ColumnIndex == 0)
                {
                    if (((System.Windows.Forms.DataGridView)(sender)).CurrentCell.RowIndex == 0)
                    {
                        ((System.Windows.Forms.DataGridView)(sender)).DataSource = TUBParam.Typetraction.GetValueList(); ;
                    }
                    else if (((System.Windows.Forms.DataGridView)(sender)).CurrentCell.RowIndex == 1)
                    {
                        ((System.Windows.Forms.DataGridView)(sender)).DataSource = TUBParam.TypeResil.GetValueList();
                    }
                }
     
            }
    tous s'execute correctement jusqu'au changement de datasource.

    L'opération n'est pas autorisée dans ce gestionnaire d'événements.</br> à System.Windows.Forms.DataGridViewColumnCollection.Add(DataGridViewColumn dataGridViewColumn)
    </br> à System.Windows.Forms.DataGridView.AutoGenerateDataBoundColumns(DataGridViewColumn[] boundColumns)
    </br> à System.Windows.Forms.DataGridView.RefreshColumns()
    </br> à System.Windows.Forms.DataGridView.RefreshColumnsAndRows()
    </br> à System.Windows.Forms.DataGridView.OnDataSourceChanged(EventArgs e)
    </br> à System.Windows.Forms.DataGridView.set_DataSource(Object value)
    </br> à CDETUB.UcEssaisMeca.traction_click(Object sender, EventArgs e)
    </br> à System.Windows.Forms.DataGridView.OnCellEnter(DataGridViewCellEventArgs e)
    </br> à System.Windows.Forms.DataGridView.OnCellEnter(DataGridViewCell& dataGridViewCell, Int32 columnIndex, Int32 rowIndex)
    </br> à System.Windows.Forms.DataGridView.OnEnter(EventArgs e)
    </br> à System.Windows.Forms.Control.NotifyEnter()
    </br> à System.Windows.Forms.ContainerControl.UpdateFocusedControl()
    </br> à System.Windows.Forms.ContainerControl.AssignActiveControlInternal(Control value)
    </br> à System.Windows.Forms.ContainerControl.ActivateControlInternal(Control control, Boolean originator)
    </br> à System.Windows.Forms.ContainerControl.ActivateControlInternal(Control control)
    </br> à System.Windows.Forms.Control.WmSetFocus(Message& m)
    </br> à System.Windows.Forms.Control.WndProc(Message& m)
    </br> à System.Windows.Forms.DataGridView.WndProc(Message& m)
    </br> à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    </br> à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    </br> à System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    </br> à System.Windows.Forms.UnsafeNativeMethods.SetFocus(HandleRef hWnd)
    </br> à System.Windows.Forms.Control.FocusInternal()
    </br> à System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)
    </br> à System.Windows.Forms.Control.WndProc(Message& m)
    </br> à System.Windows.Forms.DataGridView.WndProc(Message& m)
    </br> à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    </br> à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    </br> à System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    </br> à System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
    </br> à System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
    </br> à System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
    </br> à System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
    </br> à System.Windows.Forms.Application.RunDialog(Form form)
    </br> à System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
    </br> à System.Windows.Forms.Form.ShowDialog()
    </br> à CDETUB.main.hbtnAjouter_Click(Object sender, EventArgs e)
    </br> à System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
    </br> à System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
    </br> à System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
    </br> à System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
    </br> à System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
    </br> à System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
    </br> à System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
    </br> à System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
    </br> à System.Windows.Forms.Control.WndProc(Message& m)
    </br> à System.Windows.Forms.ScrollableControl.WndProc(Message& m)
    </br> à System.Windows.Forms.ToolStrip.WndProc(Message& m)
    </br> à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    </br> à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    </br> à System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    </br> à System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
    </br> à System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
    </br> à System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
    </br> à System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
    </br> à System.Windows.Forms.Application.Run(Form mainForm)
    </br> à CDETUB.Program.Main()

  4. #4
    Membre confirmé
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Février 2009
    Messages
    317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Finance

    Informations forums :
    Inscription : Février 2009
    Messages : 317
    Points : 560
    Points
    560
    Par défaut
    Dans le code que tu nous donnes, tu modifies le DataSource de ta DataGridView et non celui de ta DataGridViewComboBoxColumn.

    De plus, dans quel événement exécutes-tu ce bout de code ?

  5. #5
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2010
    Messages
    31
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2010
    Messages : 31
    Points : 29
    Points
    29
    Par défaut
    Bonjour merci pour vos reponse

    dans mon programme, j'appel une fonction pour me cré mon datagridview:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    DataGridViewComboBoxColumn Nom = new DataGridViewComboBoxColumn();
                Nom.Name = "Nom";
     
                Nom.HeaderText = "Type Essai";
                Nom.AutoComplete = true;
                Nom.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
    ensuite ma fonction lit une table de paramettre et ajoute la colonne si la BDD le lui indique

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    if (ds.Columns[j].ColumnName.ToString() == "Nom")
                        {
                            grd.Columns.Add(Nom);
                        }
    pour finir, ma fonction retourne le datagrid

    j'ai essayé de placer l'évement a la création du datagrid mais Nom.CellEnter n'existe pas
    j'avais aussi essayé
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    datagrid.CellEnter += new DataGridViewCellEventHandler(traction_click);
    avec le code mis plus bas mais ca ne marche pas non plus

    ou dois-je placer l'évenement? merci beaucoup

    Bonne journée a tous

  6. #6
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2010
    Messages
    31
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2010
    Messages : 31
    Points : 29
    Points
    29
    Par défaut
    Visiblement il n'est pas possible de gere separement les cellules j'ai donc mis des combos au dessus de celle du datagrid et l'orsque l'index change je modifie la valeur du datagrid.

    à moins que quelqu'un est une autre reponce à m'apporter ?

Discussions similaires

  1. [Conception] Gestion des accents dans une base de données
    Par MiJack dans le forum PHP & Base de données
    Réponses: 7
    Dernier message: 07/07/2005, 11h41
  2. gestion des boutons d'une manette : relachement
    Par backfire dans le forum DirectX
    Réponses: 1
    Dernier message: 05/01/2005, 10h13
  3. Colorier le fond des cellules d'une stringrid
    Par ORLIK dans le forum C++Builder
    Réponses: 7
    Dernier message: 09/11/2004, 21h22
  4. [VB6] Gestion des erreurs dans une dll
    Par zimba-tm dans le forum VB 6 et antérieur
    Réponses: 8
    Dernier message: 02/08/2004, 11h20
  5. Gestion des Utilisateurs depuis une application
    Par LLaurent dans le forum XMLRAD
    Réponses: 4
    Dernier message: 25/03/2003, 16h29

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