Click here to Skip to main content
15,894,720 members
Articles / Programming Languages / XML

Flexible ComboBox and EditingControl

Rate me:
Please Sign up or sign in to vote.
4.80/5 (10 votes)
30 Apr 2012CPOL6 min read 54K   5.7K   37  
Using any Control In ComboBox or in EditingControl for DataGridView
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Diagnostics;
using System.Windows.Forms;

using AnyControlComboColumn;
using System.ComponentModel;
using System.Text;
using System.Reflection;

namespace DropDownDemo {
    [Microsoft.VisualBasic.CompilerServices.DesignerGenerated()]
    public partial class Form1 : System.Windows.Forms.Form {

        //Form overrides dispose to clean up the component list.
        [System.Diagnostics.DebuggerNonUserCode()]
        protected override void Dispose(bool disposing) {
            try {
                if (disposing && components != null)
                    components.Dispose();
            } finally {
                base.Dispose(disposing);
            }
        }

        //Required by the Windows Form Designer
        private System.ComponentModel.IContainer components;

        //NOTE: The following procedure is required by the Windows Form Designer
        //It can be modified using the Windows Form Designer.  
        //Do not modify it using the code editor.
        [System.Diagnostics.DebuggerStepThrough()]
        private void InitializeComponent() {
            this.Label8 = new System.Windows.Forms.Label();
            this.rbFileListBox = new System.Windows.Forms.RadioButton();
            this.rbDirListBox = new System.Windows.Forms.RadioButton();
            this.rbCheckedListBox = new System.Windows.Forms.RadioButton();
            this.Label6 = new System.Windows.Forms.Label();
            this.CheckedListBox1 = new System.Windows.Forms.CheckedListBox();
            this.Label2 = new System.Windows.Forms.Label();
            this.Label3 = new System.Windows.Forms.Label();
            this.FileListBox1 = new Microsoft.VisualBasic.Compatibility.VB6.FileListBox();
            this.DirListBox1 = new Microsoft.VisualBasic.Compatibility.VB6.DirListBox();
            this.TableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
            this.combo1 = new AnyControlComboColumn.DropDownCombo();
            this.Label1 = new System.Windows.Forms.Label();
            this.TableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel();
            this.DataGridView1 = new System.Windows.Forms.DataGridView();
            this.NumericUpDownCol = new AnyControlComboColumn.GridColumn();
            this.ComboCol = new AnyControlComboColumn.GridColumn();
            this.Label4 = new System.Windows.Forms.Label();
            this.MaskedTextBox1 = new System.Windows.Forms.MaskedTextBox();
            this.NumericUpDown1 = new System.Windows.Forms.NumericUpDown();
            this.DataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.GridColumn1 = new AnyControlComboColumn.GridColumn();
            this.GridColumn2 = new AnyControlComboColumn.GridColumn();
            this.TableLayoutPanel1.SuspendLayout();
            this.TableLayoutPanel2.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)this.DataGridView1).BeginInit();
            ((System.ComponentModel.ISupportInitialize)this.NumericUpDown1).BeginInit();
            this.SuspendLayout();
            //
            //Label8
            //
            this.Label8.AutoSize = true;
            this.Label8.BackColor = System.Drawing.SystemColors.Control;
            this.Label8.Dock = System.Windows.Forms.DockStyle.Fill;
            this.Label8.Location = new System.Drawing.Point(0, 20);
            this.Label8.Margin = new System.Windows.Forms.Padding(0);
            this.Label8.Name = "Label8";
            this.Label8.Size = new System.Drawing.Size(98, 23);
            this.Label8.TabIndex = 22;
            this.Label8.Text = "Drop Down Control";
            this.Label8.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            //
            //rbFileListBox
            //
            this.rbFileListBox.AutoSize = true;
            this.rbFileListBox.Dock = System.Windows.Forms.DockStyle.Top;
            this.rbFileListBox.Location = new System.Drawing.Point(411, 23);
            this.rbFileListBox.Name = "rbFileListBox";
            this.rbFileListBox.Size = new System.Drawing.Size(144, 17);
            this.rbFileListBox.TabIndex = 12;
            this.rbFileListBox.Text = "File List Box";
            this.rbFileListBox.UseVisualStyleBackColor = true;
            //
            //rbDirListBox
            //
            this.rbDirListBox.AutoSize = true;
            this.rbDirListBox.Dock = System.Windows.Forms.DockStyle.Top;
            this.rbDirListBox.Location = new System.Drawing.Point(256, 23);
            this.rbDirListBox.Name = "rbDirListBox";
            this.rbDirListBox.Size = new System.Drawing.Size(144, 17);
            this.rbDirListBox.TabIndex = 13;
            this.rbDirListBox.Text = "Dir List Box";
            this.rbDirListBox.UseVisualStyleBackColor = true;
            //
            //rbCheckedListBox
            //
            this.rbCheckedListBox.AutoSize = true;
            this.rbCheckedListBox.Checked = true;
            this.rbCheckedListBox.Dock = System.Windows.Forms.DockStyle.Top;
            this.rbCheckedListBox.Location = new System.Drawing.Point(101, 23);
            this.rbCheckedListBox.Name = "rbCheckedListBox";
            this.rbCheckedListBox.Size = new System.Drawing.Size(144, 17);
            this.rbCheckedListBox.TabIndex = 14;
            this.rbCheckedListBox.TabStop = true;
            this.rbCheckedListBox.Text = "Checked List Box";
            this.rbCheckedListBox.UseVisualStyleBackColor = true;
            //
            //Label6
            //
            this.Label6.AutoSize = true;
            this.Label6.BackColor = System.Drawing.SystemColors.Control;
            this.Label6.Dock = System.Windows.Forms.DockStyle.Fill;
            this.Label6.Location = new System.Drawing.Point(0, 157);
            this.Label6.Margin = new System.Windows.Forms.Padding(0);
            this.Label6.Name = "Label6";
            this.Label6.Size = new System.Drawing.Size(98, 26);
            this.Label6.TabIndex = 19;
            this.Label6.Text = "Drop Down Combo";
            this.Label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            //
            //CheckedListBox1
            //
            this.CheckedListBox1.CheckOnClick = true;
            this.CheckedListBox1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.CheckedListBox1.FormattingEnabled = true;
            this.CheckedListBox1.Items.AddRange(new object[] {"a", "b", "c"});
            this.CheckedListBox1.Location = new System.Drawing.Point(101, 46);
            this.CheckedListBox1.Name = "CheckedListBox1";
            this.CheckedListBox1.Size = new System.Drawing.Size(144, 108);
            this.CheckedListBox1.TabIndex = 12;
            //
            //Label2
            //
            this.Label2.AutoSize = true;
            this.Label2.BackColor = System.Drawing.Color.FromArgb(Convert.ToInt32(Convert.ToByte(255)), Convert.ToInt32(Convert.ToByte(192)), Convert.ToInt32(Convert.ToByte(255)));
            this.Label2.Dock = System.Windows.Forms.DockStyle.Fill;
            this.Label2.Location = new System.Drawing.Point(248, 20);
            this.Label2.Margin = new System.Windows.Forms.Padding(0);
            this.Label2.Name = "Label2";
            this.TableLayoutPanel1.SetRowSpan(this.Label2, 2);
            this.Label2.Size = new System.Drawing.Size(5, 137);
            this.Label2.TabIndex = 15;
            this.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            //
            //Label3
            //
            this.Label3.AutoSize = true;
            this.Label3.BackColor = System.Drawing.Color.FromArgb(Convert.ToInt32(Convert.ToByte(255)), Convert.ToInt32(Convert.ToByte(192)), Convert.ToInt32(Convert.ToByte(255)));
            this.Label3.Dock = System.Windows.Forms.DockStyle.Fill;
            this.Label3.Location = new System.Drawing.Point(403, 20);
            this.Label3.Margin = new System.Windows.Forms.Padding(0);
            this.Label3.Name = "Label3";
            this.TableLayoutPanel1.SetRowSpan(this.Label3, 2);
            this.Label3.Size = new System.Drawing.Size(5, 137);
            this.Label3.TabIndex = 16;
            this.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            //
            //FileListBox1
            //
            this.FileListBox1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.FileListBox1.FormattingEnabled = true;
            this.FileListBox1.Location = new System.Drawing.Point(411, 46);
            this.FileListBox1.Name = "FileListBox1";
            this.FileListBox1.Pattern = "*.*";
            this.FileListBox1.Size = new System.Drawing.Size(144, 108);
            this.FileListBox1.TabIndex = 8;
            //
            //DirListBox1
            //
            this.DirListBox1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.DirListBox1.FormattingEnabled = true;
            this.DirListBox1.IntegralHeight = false;
            this.DirListBox1.Location = new System.Drawing.Point(256, 46);
            this.DirListBox1.Name = "DirListBox1";
            this.DirListBox1.Size = new System.Drawing.Size(144, 108);
            this.DirListBox1.TabIndex = 10;
            //
            //TableLayoutPanel1
            //
            this.TableLayoutPanel1.AutoSize = true;
            this.TableLayoutPanel1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            this.TableLayoutPanel1.ColumnCount = 6;
            this.TableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
            this.TableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
            this.TableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 5.0F));
            this.TableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
            this.TableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 5.0F));
            this.TableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
            this.TableLayoutPanel1.Controls.Add(this.DirListBox1, 3, 2);
            this.TableLayoutPanel1.Controls.Add(this.FileListBox1, 5, 2);
            this.TableLayoutPanel1.Controls.Add(this.Label3, 4, 1);
            this.TableLayoutPanel1.Controls.Add(this.Label2, 2, 1);
            this.TableLayoutPanel1.Controls.Add(this.CheckedListBox1, 1, 2);
            this.TableLayoutPanel1.Controls.Add(this.Label6, 0, 5);
            this.TableLayoutPanel1.Controls.Add(this.rbCheckedListBox, 1, 1);
            this.TableLayoutPanel1.Controls.Add(this.rbDirListBox, 3, 1);
            this.TableLayoutPanel1.Controls.Add(this.rbFileListBox, 5, 1);
            this.TableLayoutPanel1.Controls.Add(this.combo1, 1, 5);
            this.TableLayoutPanel1.Controls.Add(this.Label8, 0, 1);
            this.TableLayoutPanel1.Controls.Add(this.Label1, 0, 0);
            this.TableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Top;
            this.TableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
            this.TableLayoutPanel1.Name = "TableLayoutPanel1";
            this.TableLayoutPanel1.RowCount = 6;
            this.TableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20.0F));
            this.TableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
            this.TableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
            this.TableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
            this.TableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
            this.TableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
            this.TableLayoutPanel1.Size = new System.Drawing.Size(558, 183);
            this.TableLayoutPanel1.TabIndex = 4;
            //
            //combo1
            //
            this.TableLayoutPanel1.SetColumnSpan(this.combo1, 3);
            this.combo1.Dock = System.Windows.Forms.DockStyle.Top;
            //
            //
            //
            this.combo1.DropDownButton.Name = "";
            this.combo1.Location = new System.Drawing.Point(101, 160);
            this.combo1.Name = "combo1";
            this.combo1.Size = new System.Drawing.Size(299, 20);
            this.combo1.TabIndex = 3;
            //
            //Label1
            //
            this.Label1.AutoSize = true;
            this.Label1.BackColor = System.Drawing.Color.FromArgb(Convert.ToInt32(Convert.ToByte(255)), Convert.ToInt32(Convert.ToByte(192)), Convert.ToInt32(Convert.ToByte(255)));
            this.TableLayoutPanel1.SetColumnSpan(this.Label1, 6);
            this.Label1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.Label1.Location = new System.Drawing.Point(0, 0);
            this.Label1.Margin = new System.Windows.Forms.Padding(0);
            this.Label1.Name = "Label1";
            this.Label1.Size = new System.Drawing.Size(558, 20);
            this.Label1.TabIndex = 23;
            this.Label1.Text = "Drop Down Combo Example";
            this.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            //
            //TableLayoutPanel2
            //
            this.TableLayoutPanel2.AutoSize = true;
            this.TableLayoutPanel2.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            this.TableLayoutPanel2.ColumnCount = 2;
            this.TableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50.0F));
            this.TableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50.0F));
            this.TableLayoutPanel2.Controls.Add(this.DataGridView1, 0, 1);
            this.TableLayoutPanel2.Controls.Add(this.Label4, 0, 0);
            this.TableLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill;
            this.TableLayoutPanel2.Location = new System.Drawing.Point(0, 183);
            this.TableLayoutPanel2.Name = "TableLayoutPanel2";
            this.TableLayoutPanel2.RowCount = 2;
            this.TableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20.0F));
            this.TableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100.0F));
            this.TableLayoutPanel2.Size = new System.Drawing.Size(558, 144);
            this.TableLayoutPanel2.TabIndex = 5;
            //
            //DataGridView1
            //
            this.DataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.DataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {this.NumericUpDownCol, this.ComboCol});
            this.TableLayoutPanel2.SetColumnSpan(this.DataGridView1, 2);
            this.DataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.DataGridView1.Location = new System.Drawing.Point(3, 23);
            this.DataGridView1.Name = "DataGridView1";
            this.DataGridView1.Size = new System.Drawing.Size(552, 118);
            this.DataGridView1.TabIndex = 6;
            //
            //NumericUpDownCol
            //
            this.NumericUpDownCol.HeaderText = "Numeric Up Down";
            this.NumericUpDownCol.Name = "NumericUpDownCol";
            //
            //ComboCol
            //
            this.ComboCol.Control = this.combo1;
            this.ComboCol.HeaderText = "Combo Editing";
            this.ComboCol.Name = "ComboCol";
            this.ComboCol.Width = 254;
            //
            //Label4
            //
            this.Label4.AutoSize = true;
            this.Label4.BackColor = System.Drawing.Color.FromArgb(Convert.ToInt32(Convert.ToByte(255)), Convert.ToInt32(Convert.ToByte(192)), Convert.ToInt32(Convert.ToByte(255)));
            this.TableLayoutPanel2.SetColumnSpan(this.Label4, 2);
            this.Label4.Dock = System.Windows.Forms.DockStyle.Fill;
            this.Label4.Location = new System.Drawing.Point(0, 0);
            this.Label4.Margin = new System.Windows.Forms.Padding(0);
            this.Label4.Name = "Label4";
            this.Label4.Size = new System.Drawing.Size(558, 20);
            this.Label4.TabIndex = 24;
            this.Label4.Text = "Editing Control Example";
            this.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            //
            //MaskedTextBox1
            //
            this.MaskedTextBox1.Location = new System.Drawing.Point(241, 284);
            this.MaskedTextBox1.Mask = "&&&&&&";
            this.MaskedTextBox1.Name = "MaskedTextBox1";
            this.MaskedTextBox1.Size = new System.Drawing.Size(69, 20);
            this.MaskedTextBox1.TabIndex = 25;
            //
            //NumericUpDown1
            //
            this.NumericUpDown1.Location = new System.Drawing.Point(48, 284);
            this.NumericUpDown1.Name = "NumericUpDown1";
            this.NumericUpDown1.Size = new System.Drawing.Size(74, 20);
            this.NumericUpDown1.TabIndex = 26;
            //
            //DataGridViewTextBoxColumn1
            //
            this.DataGridViewTextBoxColumn1.HeaderText = "Column1";
            this.DataGridViewTextBoxColumn1.Name = "DataGridViewTextBoxColumn1";
            //
            //GridColumn1
            //
            this.GridColumn1.ControlText = "TextBox@@ImeMode:NoControl";
            this.GridColumn1.HeaderText = "Numeric Up Down";
            this.GridColumn1.Name = "GridColumn1";
            //
            //GridColumn2
            //
            this.GridColumn2.ControlText = "TextBox@@ImeMode:NoControl";
            this.GridColumn2.HeaderText = "Masked Text Box";
            this.GridColumn2.Name = "GridColumn2";
            this.GridColumn2.Width = 254;
            //
            //Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6.0F, 13.0F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(558, 327);
            this.Controls.Add(this.TableLayoutPanel2);
            this.Controls.Add(this.TableLayoutPanel1);
            this.Controls.Add(this.MaskedTextBox1);
            this.Controls.Add(this.NumericUpDown1);
            this.Name = "Form1";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Form1";
            this.TableLayoutPanel1.ResumeLayout(false);
            this.TableLayoutPanel1.PerformLayout();
            this.TableLayoutPanel2.ResumeLayout(false);
            this.TableLayoutPanel2.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)this.DataGridView1).EndInit();
            ((System.ComponentModel.ISupportInitialize)this.NumericUpDown1).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

            TableLayoutPanel1.Paint += new System.Windows.Forms.PaintEventHandler(TableLayoutPanel1_Paint);
            FileListBox1.GotFocus += new System.EventHandler(FileListBox1_GotFocus);
            DirListBox1.GotFocus += new System.EventHandler(DirListBox1_GotFocus);
            CheckedListBox1.GotFocus += new System.EventHandler(CheckedListBox1_GotFocus);
            rbCheckedListBox.CheckedChanged += new System.EventHandler(rbCheckedListBox_CheckedChanged);
            rbDirListBox.CheckedChanged += new System.EventHandler(rbDirListBox_CheckedChanged);
            rbFileListBox.CheckedChanged += new System.EventHandler(rbFileListBox_CheckedChanged);
            base.Load += new System.EventHandler(Form1_Load);

        }
        internal System.Windows.Forms.DataGridViewTextBoxColumn DataGridViewTextBoxColumn1;
        internal System.Windows.Forms.TableLayoutPanel TableLayoutPanel1;
        internal Microsoft.VisualBasic.Compatibility.VB6.DirListBox DirListBox1;
        internal Microsoft.VisualBasic.Compatibility.VB6.FileListBox FileListBox1;
        internal System.Windows.Forms.Label Label3;
        internal System.Windows.Forms.Label Label2;
        internal System.Windows.Forms.CheckedListBox CheckedListBox1;
        internal System.Windows.Forms.Label Label6;
        internal System.Windows.Forms.RadioButton rbCheckedListBox;
        internal System.Windows.Forms.RadioButton rbDirListBox;
        internal System.Windows.Forms.RadioButton rbFileListBox;
        internal AnyControlComboColumn.DropDownCombo combo1;
        internal System.Windows.Forms.Label Label8;
        internal System.Windows.Forms.Label Label1;
        internal System.Windows.Forms.TableLayoutPanel TableLayoutPanel2;
        internal System.Windows.Forms.Label Label4;
        internal System.Windows.Forms.MaskedTextBox MaskedTextBox1;
        internal System.Windows.Forms.NumericUpDown NumericUpDown1;
        internal System.Windows.Forms.DataGridView DataGridView1;
        internal AnyControlComboColumn.GridColumn GridColumn1;
        internal AnyControlComboColumn.GridColumn GridColumn2;
        internal AnyControlComboColumn.GridColumn NumericUpDownCol;
        internal AnyControlComboColumn.GridColumn ComboCol;

    }

}

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)


Written By
Lebanon Lebanon
ASP.Net Hosting on Linux server
---------------------------
There is a developer behind every piece of code!
DNA is too complex what about it!
No junk DNA; There is a functional role for noncoding DNA

Comments and Discussions