Click here to Skip to main content
13,662,574 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.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace SourceGrid.Controls
{
	/// <summary>
	/// Summary description for ComboBoxEx.
	/// </summary>
	public class TextBoxButton : System.Windows.Forms.UserControl
	{
		private Controls.TextBoxEx txtBox;
		private System.Windows.Forms.Button btDown;
			
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public TextBoxButton()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

			btDown.BackColor = Color.FromKnownColor(KnownColor.Control);
		}

		/// <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 Component 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.txtBox = new Controls.TextBoxEx();
			this.btDown = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// txtBox
			// 
			this.txtBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.txtBox.Name = "txtBox";
			this.txtBox.Size = new System.Drawing.Size(264, 20);
			this.txtBox.TabIndex = 0;
			this.txtBox.Text = "";
			// 
			// btDown
			// 
			this.btDown.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
			this.btDown.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
			this.btDown.Location = new System.Drawing.Point(260, 0);
			this.btDown.Name = "btDown";
			this.btDown.Size = new System.Drawing.Size(22, 64);
			this.btDown.TabIndex = 1;
			this.btDown.Text = "...";
			this.btDown.Click += new System.EventHandler(this.btDown_Click);
			// 
			// TextBoxButton
			// 
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.txtBox,
																		  this.btDown});
			this.Name = "TextBoxButton";
			this.Size = new System.Drawing.Size(282, 64);
			this.ResumeLayout(false);

		}
		#endregion

		public void FillControl()
		{
			btDown.Size = new Size(22,Height);
			btDown.Location = new Point(Width-btDown.Width,0);
			txtBox.Location = new Point(0,0);
			txtBox.Size = new Size(Width-btDown.Width,Height);
		}

		private void btDown_Click(object sender, System.EventArgs e)
		{
			OnButtonClick(EventArgs.Empty);
		}

		protected override void OnSizeChanged(EventArgs e)
		{
			base.OnSizeChanged(e);
			FillControl();
		}

//		private void txtBox_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
//		{
//			base.OnKeyDown(e);
//		}

		protected virtual void OnButtonClick(EventArgs e)
		{
			if (m_Cell==null)
				throw new ApplicationException("LoadCell not called");

			if (ButtonClick != null)
				ButtonClick(this,e);
		}

		public event EventHandler ButtonClick;

		private object m_EditObject = null;
		public object EditObject
		{
			get
			{
				if (m_Cell!=null && m_Cell.Editor!=null)
				{
					if (m_Cell.Editor.SupportStringConversion)
						return m_Cell.Editor.StringToObject(txtBox.Text);
					else
						return m_EditObject;
				}
				else
					return m_EditObject;
			}
			set
			{
				if (m_Cell!=null && m_Cell.Editor!=null)
				{
					if (m_Cell.Editor.SupportStringConversion)
						txtBox.Text = m_Cell.Editor.ObjectToString(value);
					else
						txtBox.Text = m_Cell.Editor.GetStringRappresentation(value);
				}

				m_EditObject = value;
			}
		}

		private bool ReadOnlyTextBox
		{
			get{return txtBox.ReadOnly;}
			set{txtBox.ReadOnly = value;}
		}

		private Cell m_Cell = null;
		public Cell Cell
		{
			get{return m_Cell;}
		}

		public virtual void LoadCell(Cell p_Cell, object p_StartEditValue)
		{
			m_Cell = p_Cell;

			if (p_StartEditValue!=null)
				EditObject = p_StartEditValue;
			else
				EditObject = m_Cell.Value;;

			if (m_Cell.Editor.SupportStringConversion)
				ReadOnlyTextBox = false;
			else
				ReadOnlyTextBox = true;

			SelectAllDisplayText();
		}

		public void SelectAllDisplayText()
		{
			txtBox.SelectAll();
		}
	}
}

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
Web06-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