Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
ListView control problem
Message
 
À
03/08/2005 15:51:21
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Divers
Thread ID:
01038228
Message ID:
01038290
Vues:
21
Bonnie,
Here is the code (the entire form). The important stuff that doesn't work is towards the bottom.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace TheBigTestApplication
{
	/// <summary>
	/// Summary description for Form5.
	/// </summary>
	public class Form5 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.ListView listView1;
		private System.Windows.Forms.ColumnHeader columnHeader1;
		private System.Windows.Forms.ColumnHeader columnHeader2;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.NumericUpDown numericUpDown1;
		private System.Windows.Forms.Button button3;
		private System.Windows.Forms.TextBox textBox1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form5()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			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.listView1 = new System.Windows.Forms.ListView();
			this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
			this.button3 = new System.Windows.Forms.Button();
			this.textBox1 = new System.Windows.Forms.TextBox();
			((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
			this.SuspendLayout();
			// 
			// listView1
			// 
			this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
																																								this.columnHeader1,
																																								this.columnHeader2});
			this.listView1.FullRowSelect = true;
			this.listView1.GridLines = true;
			this.listView1.Location = new System.Drawing.Point(56, 64);
			this.listView1.MultiSelect = false;
			this.listView1.Name = "listView1";
			this.listView1.Size = new System.Drawing.Size(192, 248);
			this.listView1.TabIndex = 0;
			this.listView1.View = System.Windows.Forms.View.Details;
			// 
			// columnHeader1
			// 
			this.columnHeader1.Text = "col1";
			this.columnHeader1.Width = 61;
			// 
			// columnHeader2
			// 
			this.columnHeader2.Text = "col2";
			this.columnHeader2.Width = 90;
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(320, 64);
			this.button1.Name = "button1";
			this.button1.TabIndex = 1;
			this.button1.Text = "add";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(320, 112);
			this.button2.Name = "button2";
			this.button2.TabIndex = 2;
			this.button2.Text = "edit col2";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// numericUpDown1
			// 
			this.numericUpDown1.Location = new System.Drawing.Point(456, 96);
			this.numericUpDown1.Maximum = new System.Decimal(new int[] {
																																	 41,
																																	 0,
																																	 0,
																																	 0});
			this.numericUpDown1.Name = "numericUpDown1";
			this.numericUpDown1.Size = new System.Drawing.Size(48, 20);
			this.numericUpDown1.TabIndex = 3;
			// 
			// button3
			// 
			this.button3.Location = new System.Drawing.Point(320, 160);
			this.button3.Name = "button3";
			this.button3.TabIndex = 4;
			this.button3.Text = "view";
			this.button3.Click += new System.EventHandler(this.button3_Click);
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(528, 104);
			this.textBox1.Name = "textBox1";
			this.textBox1.TabIndex = 5;
			this.textBox1.Text = "yo";
			// 
			// Form5
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(720, 566);
			this.Controls.Add(this.textBox1);
			this.Controls.Add(this.button3);
			this.Controls.Add(this.numericUpDown1);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.listView1);
			this.Name = "Form5";
			this.Text = "Form5";
			((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void button1_Click(object sender, System.EventArgs e)
		{
			ListViewItem lvi;
			ListViewItem.ListViewSubItem lvsi;

			this.listView1.BeginUpdate();
			for (int i = 0 ; i < 42 ; i++)
			{
				lvi = new ListViewItem();
				lvi.Text = (i+1).ToString();

				lvsi = new ListViewItem.ListViewSubItem();
				lvsi.Text = "Cycle "+(i+1).ToString().PadLeft(2,'0');

				lvi.SubItems.Add(lvsi);

				this.listView1.Items.Add(lvi);
			}
			this.listView1.EndUpdate();
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
//			ListViewItem lvi;
//			ListViewItem.ListViewSubItem lvsi;
//
//			this.listView1.BeginUpdate();
//
//			lvi = new ListViewItem();
//			lvi.Text = this.listView1.Items[(int)this.numericUpDown1.Value].Text;
//
//			lvsi = new ListViewItem.ListViewSubItem();
//			lvsi.Text = this.textBox1.Text;
//
//			lvi.SubItems.Add(lvsi);
//			this.listView1.Items[(int)this.numericUpDown1.Value] = lvi;
//			this.listView1.EndUpdate();
			
			// this works
			this.listView1.Items[(int)this.numericUpDown1.Value].SubItems[0].Text = this.textBox1.Text;

			// this does not work
			this.listView1.Items[(int)this.numericUpDown1.Value].SubItems[1].Text = this.textBox1.Text;


		}

		private void button3_Click(object sender, System.EventArgs e)
		{
			MessageBox.Show(this.listView1.Items[(int)this.numericUpDown1.Value].Text + Environment.NewLine + this.listView1.Items[(int)this.numericUpDown1.Value].SubItems[0].Text + Environment.NewLine + this.listView1.Items[(int)this.numericUpDown1.Value].SubItems[1].Text);
		}
	}
}
Semper ubi sub ubi.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform