CONTRÔLE LISTVIEW ÉDITABLE.

cs_Bidou Messages postés 5487 Date d'inscription dimanche 4 août 2002 Statut Membre Dernière intervention 20 juin 2013 - 12 sept. 2004 à 21:56
theclear Messages postés 12 Date d'inscription lundi 4 octobre 2004 Statut Membre Dernière intervention 24 juillet 2007 - 14 mai 2007 à 17:50
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.

https://codes-sources.commentcamarche.net/source/26119-controle-listview-editable

theclear Messages postés 12 Date d'inscription lundi 4 octobre 2004 Statut Membre Dernière intervention 24 juillet 2007
14 mai 2007 à 17:50
Merci, super ce code... J'arrivais pas à le faire marcher avec le concepteur, je suis un peu débutant mais maintenant j'ai compris et ca fonctionne très bien... Merci

Voila mon code pour ceux que ca interesse vu que j'ai pas trouvé d'exemple encore:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace MaintGest
{
/// <summary>
/// Description résumée de Form8.
/// </summary>
public class Form14 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.ColumnHeader columnHeader6;
private System.Windows.Forms.ColumnHeader columnHeader7;
private System.Windows.Forms.ColumnHeader columnHeader8;
private System.Windows.Forms.ColumnHeader columnHeader9;
private System.Windows.Forms.ColumnHeader columnHeader10;
private EditableListView listView2;
private EditableColumnInformation Colonne1;
private EditableColumnInformation Colonne2;
private MaintGest.EditableColumnInformation editableColumnInformation1;
private System.Windows.Forms.Label label2;
private System.ComponentModel.IContainer components;

public Form14()
{
//
// Requis pour la prise en charge du Concepteur Windows Forms
//
InitializeComponent();


//Initialisation interne





//
// TODO : ajoutez le code du constructeur après l'appel à InitializeComponent
//

}

/// <summary>
/// Nettoyage des ressources utilisées.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Code généré par le Concepteur Windows Form
/// <summary>
/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
/// le contenu de cette méthode avec l'éditeur de code.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(new string[] {
 "1234",
 "Pièce 1",
 "12",
 "MAN",
 "1 265 ?"}, -1);
System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem(new string[] {
 "4567",
 "Pièce 2",
 "6",
 "MAN",
 "200 ?"}, -1);
this.columnHeader6 = new System.Windows.Forms.ColumnHeader();
this.columnHeader7 = new System.Windows.Forms.ColumnHeader();
this.columnHeader8 = new System.Windows.Forms.ColumnHeader();
this.columnHeader9 = new System.Windows.Forms.ColumnHeader();
this.columnHeader10 = new System.Windows.Forms.ColumnHeader();
this.listView2 = new MaintGest.EditableListView(this.components);
this.editableColumnInformation1 = new MaintGest.EditableColumnInformation();
this.button2 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.SuspendLayout();
// 
// columnHeader6
// 
this.columnHeader6.Text = "Référence";
this.columnHeader6.Width = 69;
// 
// columnHeader7
// 
this.columnHeader7.Text = "Nom";
this.columnHeader7.Width = 253;
// 
// columnHeader8
// 
this.columnHeader8.Text = "Quantité";
// 
// columnHeader9
// 
this.columnHeader9.Text = "Fournisseur";
this.columnHeader9.Width = 110;
// 
// columnHeader10
// 
this.columnHeader10.Text = "Prix";
this.columnHeader10.Width = 63;
// 
// listView2
// 
this.listView2.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader6,
this.columnHeader7,
this.columnHeader8,
this.columnHeader9,
this.columnHeader10});
this.listView2.ColumnsInfos.AddRange(new MaintGest.EditableColumnInformation[] {
   this.editableColumnInformation1});
this.listView2.FullRowSelect = true;
this.listView2.GridLines = true;
this.listView2.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
  listViewItem1,
  listViewItem2});
this.listView2.LabelEdit = true;
this.listView2.Location = new System.Drawing.Point(50, 88);
this.listView2.Name = "listView2";
this.listView2.Size = new System.Drawing.Size(700, 312);
this.listView2.TabIndex = 21;
this.listView2.View = System.Windows.Forms.View.Details;
// 
// editableColumnInformation1
// 
this.editableColumnInformation1.ColumnIndex = 4;
this.editableColumnInformation1.ControlType = typeof(System.Windows.Forms.TextBox);
// 
// button2
// 
this.button2.BackColor = System.Drawing.Color.LightBlue;
this.button2.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.button2.ImageAlign = System.Drawing.ContentAlignment.TopCenter;
this.button2.Location = new System.Drawing.Point(456, 464);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(216, 88);
this.button2.TabIndex = 17;
this.button2.Text = "Valider";
this.button2.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
// 
// button1
// 
this.button1.BackColor = System.Drawing.Color.LightBlue;
this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.button1.ImageAlign = System.Drawing.ContentAlignment.TopCenter;
this.button1.Location = new System.Drawing.Point(88, 464);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(216, 88);
this.button1.TabIndex = 18;
this.button1.Text = "Annuler";
this.button1.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
// 
// label2
// 
this.label2.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label2.Location = new System.Drawing.Point(120, 48);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(360, 24);
this.label2.TabIndex = 32;
this.label2.Text = "Merci de renseigner les prix négociés";
// 
// Form11
// 
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
this.ClientSize = new System.Drawing.Size(792, 566);
this.Controls.Add(this.listView2);
this.Controls.Add(this.label2);
this.Controls.Add(this.button1);
this.Controls.Add(this.button2);
this.Name = "Form11";
this.Text = "Bons de commandes";
this.ResumeLayout(false);

}
#endregion



private void button1_Click(object sender, System.EventArgs e)
{
GestionVariables.getInstance().FermetureDanger(this);
}

private void button2_Click(object sender, System.EventArgs e)
{
Form9 form9 = new Form9();
form9.Owner = this.Owner;
form9.Show();
this.Hide();
}
}
}



Désolé c'est ma form14 donc il n'y a pas tout ce qui faut si vous le voulez dans la form1... Il suffit de le mettre dans une 2eme form et d'y faire appel de la 2eme... Le principal c'est l'appel à la class qui nous interesse et le paramétrage du composant.

Bye
Merci encore à BAFM
alhabas Messages postés 11 Date d'inscription mercredi 21 juillet 2004 Statut Membre Dernière intervention 31 août 2005
25 juil. 2005 à 19:34
Merci enfin ça marche.
BaFM Messages postés 64 Date d'inscription mercredi 24 juillet 2002 Statut Membre Dernière intervention 26 novembre 2009
25 juil. 2005 à 13:17
Il faut faire les liaisons aux évènements manuellement aussi.
Pour information, la liaison à un évènement se fait par :
<nomobjet>.<évènement> += new <type délégué>(<méthode>);
MG
alhabas Messages postés 11 Date d'inscription mercredi 21 juillet 2004 Statut Membre Dernière intervention 31 août 2005
25 juil. 2005 à 10:38
Merci d'abord pour l'aide,
Finalement ça marche. Mais une autre fois j'arrive pas à gérer les événement sur le contrôle,
malgré la récupération de ce dernier à l'aide de la propriété Editecontrole

Merci.
BaFM Messages postés 64 Date d'inscription mercredi 24 juillet 2002 Statut Membre Dernière intervention 26 novembre 2009
24 juil. 2005 à 14:56
Alhabas, il faut le remplir manuellement le control. La propriété de EditableColumnInfoInformation.EditControl qui te retourne le control associé qu'il faut convertir en le type sélectionné te retourne le contrôle qui sera affiché lors de la demande d'édition de la colonne. A partir de la, tu pourra ajouter les éléments. De plus, grâce à l'évènement ExtendedBeforeLabelEdit, tu peut remplir la liste déroulante en fonction de l'élément sélectionné.

PS : Je suis actuellement en train de travailler sur un composant du même type mais sans dériver de la ListView du système.

MG
alhabas Messages postés 11 Date d'inscription mercredi 21 juillet 2004 Statut Membre Dernière intervention 31 août 2005
24 juil. 2005 à 14:13
Bonjour a tous,
votre contrôle est excellent.
mais malheuresement j'arrive pas à remplire le controle ComboBox est-ce que tu peut m'aider.
BaFM Messages postés 64 Date d'inscription mercredi 24 juillet 2002 Statut Membre Dernière intervention 26 novembre 2009
26 nov. 2004 à 13:18
C'est normal, il faut avoir un élément a éditer pour que le mode d'édition fonctionne. De plus tu n'a pas activé la propriété LabelEdit (hérité de ListView) qui permet d'indiquer que l'édition est authorisée.

L'exemple sera bientôt inclus dans l'aide, bientôt...

MG
cs_revlis Messages postés 41 Date d'inscription mardi 15 juillet 2003 Statut Membre Dernière intervention 7 décembre 2004
26 nov. 2004 à 08:56
j'ai du rater quelque chose :
j'ai mis ton control sur un form vide, je l'ai mis en mode detail, j'ai ajouter des colonnes, des colonnes infos (qui pointent vers les colonnes via la columnindex) et des ligne, et lorsque je lance le prog, j'ai un list view tout a fait normal.....


je colle ma source pour voir ce qu'il manque (ca serait peut etre sympa d'u en ajouter une dans ton zip ;) )

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace tests
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private MyControls.EditableListView editableListView1;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private MyControls.EditableColumnInformation editableColumnInformation1;
private MyControls.EditableColumnInformation editableColumnInformation2;
private System.ComponentModel.IContainer components;

public Form1()
{
InitializeComponent();
}

protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(new string[] {
"1",
"2"}, -1);
System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem(new string[] {
"3",
"4"}, -1);
this.editableListView1 = new MyControls.EditableListView(this.components);
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.editableColumnInformation1 = new MyControls.EditableColumnInformation();
this.editableColumnInformation2 = new MyControls.EditableColumnInformation();
this.SuspendLayout();
//
// editableListView1
//
this.editableListView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2});
this.editableListView1.ColumnsInfos.AddRange(new MyControls.EditableColumnInformation[] {
this.editableColumnInformation1,
this.editableColumnInformation2});
this.editableListView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
listViewItem1,
listViewItem2});
this.editableListView1.Location = new System.Drawing.Point(24, 64);
this.editableListView1.Name = "editableListView1";
this.editableListView1.Size = new System.Drawing.Size(256, 200);
this.editableListView1.TabIndex = 1;
this.editableListView1.View = System.Windows.Forms.View.Details;
//
// editableColumnInformation1
//
this.editableColumnInformation1.ColumnIndex = 0;
this.editableColumnInformation1.ControlType = typeof(System.Windows.Forms.TextBox);
//
// editableColumnInformation2
//
this.editableColumnInformation2.ColumnIndex = 1;
this.editableColumnInformation2.ControlType = typeof(System.Windows.Forms.TextBox);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.editableListView1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
}
BaFM Messages postés 64 Date d'inscription mercredi 24 juillet 2002 Statut Membre Dernière intervention 26 novembre 2009
7 nov. 2004 à 18:10
Et voilà, enfin un peu d'aide.
Nix Messages postés 831 Date d'inscription samedi 15 mai 1999 Statut Membre Dernière intervention 18 juillet 2009
13 sept. 2004 à 11:38
J'ai eu un pb d'espace disk, peux-tu re-uploader ton zip stp (c'est corrigé)
Désolé :p
Merci
BaFM Messages postés 64 Date d'inscription mercredi 24 juillet 2002 Statut Membre Dernière intervention 26 novembre 2009
13 sept. 2004 à 11:24
Simple, parce que je sais pas faire et que je me suis pas encore penché sur le problème hihi, mais merci pour l'info.
cs_coq Messages postés 6349 Date d'inscription samedi 1 juin 2002 Statut Membre Dernière intervention 2 août 2014 101
13 sept. 2004 à 10:41
comme tu as mit les commentaires xml pourquoi ne pas mettre ton fichier dans un projet "bibliotheque de classes" et générer le chm avec ndoc ?
BaFM Messages postés 64 Date d'inscription mercredi 24 juillet 2002 Statut Membre Dernière intervention 26 novembre 2009
12 sept. 2004 à 22:07
Pour l'instant le fichier d'aide n'est que en projet. J'ai quand même mit en peu de temps a faire ce petit contrôle. C vrai que les 1400+ lignes font peur (11 types) mais en fait c'est assez simple, une fois la logique comprise.
Mais j'y pense a faire la petite aide, je metterais peux-être un exemple d'application (le formulaire qui m'a permit de tester).

NB : Je l'ai testé dans mon application final, et ca fonctionne bien, le comportement que j'avais espéré fonctionne.
PS : Je vais essayer de me motiver pour faire l'aide le plus rapidement afin que vous puissiez utiliser toutes les fonctionalités
cs_Bidou Messages postés 5487 Date d'inscription dimanche 4 août 2002 Statut Membre Dernière intervention 20 juin 2013 61
12 sept. 2004 à 21:56
Tout cela m'a l'air fort intéressant et très pratique.
J'ai que très rapidement testé et ça m'intéresse beaucoup mais......

....selon moi, il manque quand même une doc, compte tenu de la complexité du control, non?
Rejoignez-nous