Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

A Practical Use of the MVC Pattern

, 8 Jan 2007 CPOL
Another approach to the MVC pattern
using System.Data;
using System.Windows.Forms;
using MvcExample.Models;

namespace MvcExample.Views
{
	public class View_List_Income : BaseView
	{
		#region Windows Form Designer generated code
		private System.Windows.Forms.ListView lvw;
		private System.Windows.Forms.ColumnHeader colYear;
		private System.Windows.Forms.ColumnHeader colIncome;

		private System.ComponentModel.Container components = null;

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				if (components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose(disposing);
		}

		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.lvw = new System.Windows.Forms.ListView();
			this.colYear = new System.Windows.Forms.ColumnHeader();
			this.colIncome = new System.Windows.Forms.ColumnHeader();
			this.SuspendLayout();
			// 
			// butClose
			// 
			this.butClose.Location = new System.Drawing.Point(320, 400);
			this.butClose.Name = "butClose";
			// 
			// progressBar
			// 
			this.progressBar.Location = new System.Drawing.Point(8, 408);
			this.progressBar.Name = "progressBar";
			this.progressBar.Size = new System.Drawing.Size(304, 16);
			// 
			// lvw
			// 
			this.lvw.Anchor = ((System.Windows.Forms.AnchorStyles) ((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
				| System.Windows.Forms.AnchorStyles.Left)
				| System.Windows.Forms.AnchorStyles.Right)));
			this.lvw.Columns.AddRange(new System.Windows.Forms.ColumnHeader[]
				{
					this.colYear,
					this.colIncome
				});
			this.lvw.FullRowSelect = true;
			this.lvw.GridLines = true;
			this.lvw.Location = new System.Drawing.Point(10, 7);
			this.lvw.Name = "lvw";
			this.lvw.Size = new System.Drawing.Size(390, 385);
			this.lvw.TabIndex = 2;
			this.lvw.View = System.Windows.Forms.View.Details;
			// 
			// colYear
			// 
			this.colYear.Text = "Year";
			this.colYear.Width = 120;
			// 
			// colIncome
			// 
			this.colIncome.Text = "Income";
			this.colIncome.Width = 120;
			// 
			// View_List_Income
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(408, 427);
			this.Controls.Add(this.lvw);
			this.Name = "View_List_Income";
			this.Text = "Textual representation of test data";
			this.Controls.SetChildIndex(this.progressBar, 0);
			this.Controls.SetChildIndex(this.lvw, 0);
			this.Controls.SetChildIndex(this.butClose, 0);
			this.ResumeLayout(false);

		}
		#endregion

		#region constructor
		public View_List_Income()
		{
			InitializeComponent();
		}
		#endregion constructor

		#region overriden methods
		protected override void ContinueUpdateView(ref DataSet ds)
		{
			if (ds.Tables.Count > 0)
			{
				lvw.BeginUpdate();
				lvw.Items.Clear();

				string colYear = EnumIncome.Year.ToString();
				string colIncome = EnumIncome.Income.ToString();

				for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
				{
					DataRow row = ds.Tables[0].Rows[i];

					ListViewItem li = new ListViewItem(row[colYear].ToString());
					li.SubItems.Add(
						string.Format("{0:#.##}", row[colIncome]));

					lvw.Items.Add(li);
				}

				lvw.EndUpdate();
			} // if
		}
		#endregion overriden methods
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Zoltan Balazs
Software Developer
Romania Romania
I've did some programming for Macintosh a few years back and working with Microsoft technologies since then.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 8 Jan 2007
Article Copyright 2007 by Zoltan Balazs
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid