Click here to Skip to main content
13,666,809 members
Click here to Skip to main content

Stats

3M views
19.7K downloads
994 bookmarked
Posted 19 Jan 2003
Licenced MIT

SourceGrid - Open Source C# Grid Control

, 4 Aug 2013
SourceGrid is a free open source grid control. Supports virtual grid, custom cells and editors, advanced formatting options and many others features
SourceGrid2
References
SourceLibrary.dll
vssver.scc
SampleProject
App.ico
bin
Release
SampleProject.exe
SourceGrid2.dll
SourceLibrary.dll
Extensions
Add.ico
ArrowDown.ICO
ArrowUp.ICO
Delete.ICO
Refresh.ico
vssver.scc
Samples
CalcioSmall.bmp
FACE00.ICO
FACE01.ICO
FACE02.ICO
FACE04.ICO
new.bmp
vssver.scc
SourceGrid
BehaviorModels
vssver.scc
bin
Release
SourceGrid2.dll
SourceLibrary.dll
vssver.scc
Cells
vssver.scc
Common
Icons
CheckBoxChecked.ico
CheckBoxCheckedDisable.ico
CheckBoxCheckedSel.ico
CheckBoxUnChecked.ico
CheckBoxUnCheckedDisable.ico
CheckBoxUnCheckedSel.ico
clear.ico
copy.ico
cut.ico
DeleteCol.ico
DeleteRow.ico
InsertCol.ico
InsertRow.ico
paste.ico
properties.ico
SortDown.ico
SortUp.ico
Thumbs.db
vssver.scc
vssver.scc
DataModels
vssver.scc
Grid.bmp
Grids
vssver.scc
GridVirtual.bmp
SourceGrid2.snk
VisualModels
vssver.scc
SourceGrid
DemoProject
App.ico
bin
Release
DemoProject.exe
SourceGrid.dll
SourceLibrary.dll
FACE00.ICO
FACE01.ICO
FACE02.ICO
FACE04.ICO
new.bmp
PropertyStyleGrid
WorksheetStyleGrid
References
SourceLibrary.dll
SourceGrid
bin
Release
SourceGrid.dll
Cells
Models
PropertyStyleGrid
SourceGrid.snk
TypeCreator
Utility
Chris.Beckett.MenuImageLib
SubItem16.ico
Control
Controls
Icons
CheckBoxChecked.ico
CheckBoxCheckedDisable.ico
CheckBoxCheckedSel.ico
CheckBoxUnChecked.ico
CheckBoxUnCheckedDisable.ico
CheckBoxUnCheckedSel.ico
clear.ico
copy.ico
cut.ico
DeleteCol.ico
DeleteRow.ico
InsertCol.ico
InsertRow.ico
paste.ico
properties.ico
SortDown.ico
SortUp.ico
WorksheetStyleGrid
using System;
using System.Windows.Forms;

namespace SourceGrid.Models
{
	/// <summary>
	/// Summary description for NumericUpDownEditor.
	/// </summary>
	public class EditorNumericUpDown : EditorControlBase
	{
		private decimal m_Maximum = 100;
		private decimal m_Minimum = 0;
		private decimal m_Increment = 1;
		public EditorNumericUpDown()
		{
		}
		
		public EditorNumericUpDown(Type p_CellType, decimal p_Maximum, decimal p_Minimum, decimal p_Increment):this()
		{
			if (p_CellType==null || p_CellType == typeof(int) ||
				p_CellType == typeof(long) || p_CellType == typeof(decimal))
			{
				CellType = p_CellType;
				m_Maximum = p_Maximum;
				m_Minimum = p_Minimum;
				m_Increment = p_Increment;
			}
			else
				throw new ApplicationException("Invalid CellType expected long, int or decimal");
		}

		#region Edit Control
		public override Control CreateEditorControl()
		{
			System.Windows.Forms.NumericUpDown l_Control = new System.Windows.Forms.NumericUpDown();
			l_Control.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			l_Control.Maximum = m_Maximum;
			l_Control.Minimum = m_Minimum;
			l_Control.Increment = m_Increment;
			return l_Control;
		}
		public System.Windows.Forms.NumericUpDown NumericUpDown
		{
			get{return (System.Windows.Forms.NumericUpDown)EditControl;}
		}
		#endregion

		public override void StartEdit(Cell p_Cell, object p_StartEditValue)
		{
			base.StartEdit(p_Cell, p_StartEditValue);

			if (p_StartEditValue != null)
			{
				SetValueToControl(p_StartEditValue);
			}
			else
			{
				SetValueToControl(p_Cell.Value);
			}
		}

		public override object GetEditedValue()
		{
			return GetValueFromControl();
		}

		private object GetValueFromControl()
		{
			if (base.CellType == null)
				return NumericUpDown.Value;
			if (base.CellType == typeof(decimal))
				return NumericUpDown.Value;
			if (base.CellType == typeof(int))
				return (int)(NumericUpDown.Value);
			if (base.CellType == typeof(long))
				return (long)(NumericUpDown.Value);

			throw new ApplicationException("Invalid type of the cell expected decimal, long or int");
		}

		private void SetValueToControl(object p_Value)
		{
			if (p_Value is decimal)
				NumericUpDown.Value = (decimal)p_Value;
			else if (p_Value is long)
				NumericUpDown.Value = (decimal)((long)p_Value);
			else if (p_Value is int)
				NumericUpDown.Value = (decimal)((int)p_Value);
			else if (p_Value == null)
				NumericUpDown.Value = NumericUpDown.Minimum;
			else
				throw new ApplicationException("Invalid value, expected Decimal, Int or Long");
		}
	}
}

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 MIT License

Share

About the Author

Davide Icardi
Software Developer
Italy Italy
No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.180810.1 | Last Updated 4 Aug 2013
Article Copyright 2003 by Davide Icardi
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid