Click here to Skip to main content
15,893,722 members
Articles / Programming Languages / C#

SourceGrid - Open Source C# Grid Control

Rate me:
Please Sign up or sign in to vote.
4.94/5 (429 votes)
4 Aug 2013MIT24 min read 4.9M   23.7K   1K  
SourceGrid is a free open source grid control. Supports virtual grid, custom cells and editors, advanced formatting options and many others features
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;

using System.Windows.Forms;
using System.Drawing.Design;

namespace SourceGrid.Controls
{
	public class TextBoxButtonUITypeEditor : TextBoxButton, IServiceProvider, System.Windows.Forms.Design.IWindowsFormsEditorService
	{
		private System.ComponentModel.IContainer components = null;

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

			// TODO: Add any initialization after the 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 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()
		{
			components = new System.ComponentModel.Container();
		}
		#endregion


		protected override void OnButtonClick(EventArgs e)
		{
			base.OnButtonClick(e);
			ShowUITypeEditor();
		}

		protected virtual void ShowUITypeEditor()
		{
			try
			{
				UITypeEditorEditStyle l_Style = m_UITypeEditor.GetEditStyle();
				if (l_Style == UITypeEditorEditStyle.DropDown ||
					l_Style == UITypeEditorEditStyle.Modal)
				{
					object tmp = m_UITypeEditor.EditValue(this,EditObject);
					EditObject = tmp;
				}
			}
			catch(Exception err)
			{
				MessageBox.Show(err.Message,"Error");
			}
		}

		private UITypeEditor m_UITypeEditor;
		public UITypeEditor UITypeEditor
		{
			get{return m_UITypeEditor;}
			set{m_UITypeEditor = value;}
		}

		//IServiceProvider
		System.Object IServiceProvider.GetService ( System.Type serviceType )
		{
			//modal
			if (serviceType == typeof(System.Windows.Forms.Design.IWindowsFormsEditorService))
				return this;

			return null;
		}

		#region System.Windows.Forms.Design.IWindowsFormsEditorService

		private SourceLibrary.Windows.Forms.DropDownCustom m_dropDown = null;
		public virtual void CloseDropDown ()
		{
			if (m_dropDown!=null)
			{
				m_dropDown.Hide();
			}
		}

		public virtual void DropDownControl ( System.Windows.Forms.Control control )
		{
			//NB facendo il close o il dispose probabilmente qualcosa non funziona correttamente infatti non si riesce poi pi� ad accedere all'editor
			//using(m_dropDown = new ctlDropDownCustom(this))

			m_dropDown = new SourceLibrary.Windows.Forms.DropDownCustom(this, control);
			//m_dropDown.ShowDialog(this); //con questo sistema non riuscivo a chiudere il controllo quando l'utente disattivava la finestra
			m_dropDown.ShowDropDown();
			m_dropDown = null;
			//TODO si potrebbe provare a togliere prima i childs e poi fare il dispose
			//m_dropDown.Close(); //non si pu� chiudere ne fare il dispose altrimenti il chiamante non riesce pi� ad accedere ai controlli figlio 
		}

		public virtual System.Windows.Forms.DialogResult ShowDialog ( System.Windows.Forms.Form dialog )
		{
			return dialog.ShowDialog(this);
		}
		#endregion
	}
}

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


Written By
Software Developer
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions