Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Posted
Updated 1-Apr-14 2:38am
v4
Comments
[no name] 31-Mar-14 9:26am    
This is just an unformatted code dump. No one is going to go through this and try and figure out what it is that you are trying to do. Especially when you did not bother to explain to us what you are trying to do or what the problem is.
Maciej Los 31-Mar-14 12:02pm    
Do not post entire code. Please, post only those parts which is necessary to explain your issue.

Here[^] is a collection of avalible column types in the Windows Forms DataGridView. As you can see, there is nothing like numeric column.

Example:
C#
DataTable DgvDt = new DataTable();

    DataColumn dc = new DataColumn("StringColumn", Type.GetType("System.String"));
    DgvDt.Columns.Add(dc);
    dc = new DataColumn("IntegerColumn", Type.GetType("System.Int32"));
    DgvDt.Columns.Add(dc);

    dataGridView1.DataSource = DgvDt;

As you can see, second column is "numeric" column.
 
Share this answer
 
public partial class FrmMainCustomercs : Form
{

public FrmMainCustomercs(Form parentForm)
{
if (parentForm == null)
{
throw new ArgumentNullException("parentForm");
}
InitializeComponent();
ParentForm = parentForm;
AddEditControl();
BindDataGrid();
}


#region Method
///
/// Method will add the Edit Control user Control.
///

private void AddEditControl()
{
FrmAddEditCustomer addEditCustomer = new FrmAddEditCustomer();
AddEditPanel panel = new AddEditPanel(addEditCustomer);
pnlEditControl.Controls.Add(panel);
}

private void BindDataGrid()
{
using (SqlCeConnection conn = Connection)
{
conn.Open();
using (SqlCeCommand cmd = new SqlCeCommand("Select Customer_Name,Customer_Code From MainCustomer", conn))
{
SqlCeDataAdapter adp = new SqlCeDataAdapter(cmd);
DataSet ds = new DataSet();
adp.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
}
}

#endregion
protected override void OnClosed(EventArgs e)
{
ParentForm.MdiParent.Show();
base.OnClosed(e);
}

#region EventHandler
private void button1_Click(object sender, EventArgs e)
{
using (SqlCeConnection conn = Connection)
{
conn.Open();
using (SqlCeCommand cmd = new SqlCeCommand("insert into MainCustomer(Customer_Name,Customer_Code,Customer_Account,Customer_Category) values ( @cust_name,@cust_code,@cust_account,@cust_category)", conn))
{
cmd.Parameters.AddWithValue("@cust_name", txtCustomerName.Text);
cmd.Parameters.AddWithValue("@cust_code", cmb_CustomerCode.SelectedText);
cmd.Parameters.AddWithValue("@cust_account", cmbCustomerAccount.SelectedText);
cmd.Parameters.AddWithValue("@cust_category", cmbCustomerCategory.SelectedText);
cmd.CommandType = System.Data.CommandType.Text;
int result = cmd.ExecuteNonQuery();
if (result > 0)
{
MessageBox.Show("Huuray ");
}
}
}
}
#endregion

#region Properties
public new Form ParentForm { get; set; }

///
/// return connection to sqlceserver
///

private SqlCeConnection Connection
{
get
{
string connectionString =ConfigurationManager.ConnectionStrings["Database1ConnectionString"].ConnectionString;
return new SqlCeConnection(connectionString);
}
}


#endregion


}










#region Windows Form Designer generated code

///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.pnlEditControl = new System.Windows.Forms.Panel();
this.panel1 = new System.Windows.Forms.Panel();
this.panel2 = new System.Windows.Forms.Panel();
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.txtCustomerName = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.cmbCustomerAccount = new System.Windows.Forms.ComboBox();
this.label3 = new System.Windows.Forms.Label();
this.cmb_CustomerCode = new System.Windows.Forms.ComboBox();
this.label4 = new System.Windows.Forms.Label();
this.cmbCustomerCategory = new System.Windows.Forms.ComboBox();
this.button2 = new System.Windows.Forms.Button();
this.dataGridView1 = new System.Windows.Forms.DataGridView();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout();
this.tableLayoutPanel1.SuspendLayout();
this.panel1.SuspendLayout();
this.panel2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.SuspendLayout();
//
// splitContainer1
//
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer1.FixedPanel = System.Windows.Forms.FixedPanel.Panel1;
this.splitContainer1.Location = new System.Drawing.Point(0, 0);
this.splitContainer1.Name = "splitContainer1";
//
// splitContainer1.Panel1
//
this.splitContainer1.Panel1.Controls.Add(this.tableLayoutPanel1);
this.splitContainer1.Panel1MinSize = 200;
//
// splitContainer1.Panel2
//
this.splitContainer1.Panel2.Controls.Add(this.panel2);
this.splitContainer1.Panel2.Controls.Add(this.panel1);
this.splitContainer1.Size = new System.Drawing.Size(757, 452);
this.splitContainer1.SplitterDistance = 267;
this.splitContainer1.TabIndex = 0;
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.ColumnCount = 1;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.Controls.Add(this.pnlEditControl, 0, 0);
this.tableLayoutPanel1.Controls.Add(this.dataGridView1, 0, 1);
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 2;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 402F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(267, 452);
this.tableLayoutPanel1.TabIndex = 0;
//
// pnlEditControl
//
this.pnlEditControl.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.pnlEditControl.BackColor = System.Drawing.Color.Gainsboro;
this.pnlEditControl.Location = new System.Drawing.Point(3, 3);
this.pnlEditControl.Name = "pnlEditControl";
this.pnlEditControl.Size = new System.Drawing.Size(261, 44);
this.pnlEditControl.TabIndex = 0;
//
// panel1
//
this.panel1.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.panel1.AutoSize = true;
this.panel1.Controls.Add(this.button2);
this.panel1.Controls.Add(this.cmbCustomerCategory);
this.panel1.Controls.Add(this.label4);
this.panel1.Controls.Add(this.cmb_CustomerCode);
this.panel1.Controls.Add(this.label3);
this.panel1.Controls.Add(this.cmbCustomerAccount);
this.panel1.Controls.Add(this.label2);
this.panel1.Controls.Add(this.txtCustomerName);
this.panel1.Controls.Add(this.label1);
this.panel1.Location = new System.Drawing.Point(3, 3);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(480, 413);
this.panel1.TabIndex = 0;
//
// panel2
//
this.panel2.Controls.Add(this.button1);
this.panel2.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panel2.Location = new System.Drawing.Point(0, 422);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(486, 30);
this.panel2.TabIndex = 1;
//
// button1
//
this.button1.Location = new System.Drawing.Point(190, 4);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "Save";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(3, 14);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(35, 13);
this.label1.TabIndex = 0;
this.label1.Text = "Name";
//
// txtCustomerName
//
this.txtCustomerName.Location = new System.Drawing.Point(70, 11);
this.txtCustomerName.Name = "txtCustomerName";
this.txtCustomerName.Size = new System.Drawing.Size(404, 20);
this.txtCustomerName.TabIndex = 1;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(19, 61);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(46, 13);
this.label2.TabIndex = 2;
this.label2.Text = "Cutomer";
//
// cmbCustomerAccount
//
this.cmbCustomerAccount.FormattingEnabled = true;
this.cmbCustomerAccount.Items.AddRange(new object[] {
"001",
"002"});
this.cmbCustomerAccount.Location = new System.Drawing.Point(71, 57);
this.cmbCustomerAccount.Name = "cmbCustomerAccount";
this.cmbCustomerAccount.Size = new System.Drawing.Size(96, 21);
this.cmbCustomerAccount.TabIndex = 3;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(166, 62);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(32, 13);
this.label3.TabIndex = 4;
this.label3.Text = "Code";
//
// cmb_CustomerCode
//
this.cmb_CustomerCode.FormattingEnabled = true;
this.cmb_CustomerCode.Items.AddRange(new object[] {
"001",
"002"});
this.cmb_CustomerCode.Location = new System.Drawing.Point(200, 58);
this.cmb_CustomerCode.Name = "cmb_CustomerCode";
this.cmb_CustomerCode.Size = new System.Drawing.Size(96, 21);
this.cmb_CustomerCode.TabIndex = 5;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(300, 63);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(49, 13);
this.label4.TabIndex = 6;
this.label4.Text = "Category";
//
// cmbCustomerCategory
//
this.cmbCustomerCategory.FormattingEnabled = true;
this.cmbCustomerCategory.Items.AddRange(new object[] {
"001",
"002"});
this.cmbCustomerCategory.Location = new System.Drawing.Point(350, 59);
this.cmbCustomerCategory.Name = "cmbCustomerCategory";
this.cmbCustomerCategory.Size = new System.Drawing.Size(96, 21);
this.cmbCustomerCategory.TabIndex = 7;
//
// button2
//
this.button2.Location = new System.Drawing.Point(450, 58);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(24, 23);
this.button2.TabIndex = 8;
this.button2.Text = "...";
this.button2.UseVisualStyleBackColor = true;
//
// dataGridView1
//
this.dataGridView1.AllowUserToAddRows = false;
this.dataGridView1.AllowUserToResizeColumns = false;
dataGridViewCellStyle1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(64)))), ((int)(((byte)(0)))));
this.dataGridView1.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1;
this.dataGridView1.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.dataGridView1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Location = new System.Drawing.Point(3, 53);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.Size = new System.Drawing.Size(261, 396);
this.dataGridView1.TabIndex = 1;
//
// FrmMainCustomercs
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(757, 452);
this.Controls.Add(this.splitContainer1);
this.Name = "FrmMainCustomercs";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "FrmMainCustomercs";
this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel2.ResumeLayout(false);
this.splitContainer1.Panel2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
this.splitContainer1.ResumeLayout(false);
this.tableLayoutPanel1.ResumeLayout(false);
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
this.ResumeLayout(false);

}

#endregion

private System.Windows.Forms.SplitContainer splitContainer1;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.Panel pnlEditControl;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.ComboBox cmbCustomerCategory;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.ComboBox cmb_CustomerCode;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.ComboBox cmbCustomerAccount;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox txtCustomerName;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.DataGridView dataGridView1;






C#
public partial class AddEditPanel : UserControl
    {
        public AddEditPanel()
        {
            InitializeComponent();
        }

        public AddEditPanel(Form formAddEdit)
        {
            if (formAddEdit == null)
            {
                throw new ArgumentNullException("formAddEdit");
            }

            InitializeComponent();
            AddEditForm = formAddEdit;
            this.lblfrmheader.Text = formAddEdit.Text;
        }

        #region Property
        public Form AddEditForm { get; set; }
        #endregion

    }





#region Component Designer generated code

///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.psnelContainer = new System.Windows.Forms.Panel();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.addbutton = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.cmbSearchcriteria = new System.Windows.Forms.ComboBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.button3 = new System.Windows.Forms.Button();
this.lblfrmheader = new System.Windows.Forms.Label();
this.psnelContainer.SuspendLayout();
this.tableLayoutPanel1.SuspendLayout();
this.SuspendLayout();
//
// psnelContainer
//
this.psnelContainer.Controls.Add(this.tableLayoutPanel1);
this.psnelContainer.Controls.Add(this.lblfrmheader);
this.psnelContainer.Dock = System.Windows.Forms.DockStyle.Fill;
this.psnelContainer.Location = new System.Drawing.Point(0, 0);
this.psnelContainer.Name = "psnelContainer";
this.psnelContainer.Size = new System.Drawing.Size(357, 36);
this.psnelContainer.TabIndex = 0;
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.ColumnCount = 6;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 61F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 105F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 32F));
this.tableLayoutPanel1.Controls.Add(this.addbutton, 0, 0);
this.tableLayoutPanel1.Controls.Add(this.button1, 1, 0);
this.tableLayoutPanel1.Controls.Add(this.button2, 2, 0);
this.tableLayoutPanel1.Controls.Add(this.cmbSearchcriteria, 3, 0);
this.tableLayoutPanel1.Controls.Add(this.textBox1, 4, 0);
this.tableLayoutPanel1.Controls.Add(this.button3, 5, 0);
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Right;
this.tableLayoutPanel1.Location = new System.Drawing.Point(99, 0);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 1;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(258, 36);
this.tableLayoutPanel1.TabIndex = 1;
//
// addbutton
//
this.addbutton.Dock = System.Windows.Forms.DockStyle.Fill;
this.addbutton.Location = new System.Drawing.Point(3, 3);
this.addbutton.Name = "addbutton";
this.addbutton.Size = new System.Drawing.Size(14, 30);
this.addbutton.TabIndex = 0;
this.addbutton.Text = "+";
this.addbutton.UseVisualStyleBackColor = true;
//
// button1
//
this.button1.Dock = System.Windows.Forms.DockStyle.Fill;
this.button1.Location = new System.Drawing.Point(23, 3);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(14, 30);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
//
// button2
//
this.button2.Dock = System.Windows.Forms.DockStyle.Fill;
this.button2.Location = new System.Drawing.Point(43, 3);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(14, 30);
this.button2.TabIndex = 2;
this.button2.Text = "-";
this.button2.UseVisualStyleBackColor = true;
//
// cmbSearchcriteria
//
this.cmbSearchcriteria.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.cmbSearchcriteria.FormattingEnabled = true;
this.cmbSearchcriteria.Location = new System.Drawing.Point(63, 7);
this.cmbSearchcriteria.Name = "cmbSearchcriteria";
this.cmbSearchcriteria.Size = new System.Drawing.Size(55, 21);
this.cmbSearchcriteria.TabIndex = 3;
//
// textBox1
//
this.textBox1.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.textBox1.Location = new System.Drawing.Point(124, 8);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(99, 20);
this.textBox1.TabIndex = 4;
//
// button3
//
this.button3.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.button3.Location = new System.Drawing.Point(229, 6);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(26, 23);
this.button3.TabIndex = 5;
this.button3.Text = "button3";
this.button3.UseVisualStyleBackColor = true;
//
// lblfrmheader
//
this.lblfrmheader.AutoSize = true;
this.lblfrmheader.Location = new System.Drawing.Point(3, 10);
this.lblfrmheader.Name = "lblfrmheader";
this.lblfrmheader.Size = new System.Drawing.Size(0, 13);
this.lblfrmheader.TabIndex = 0;
//
// AddEditPanel
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.psnelContainer);
this.Name = "AddEditPanel";
this.Size = new System.Drawing.Size(357, 36);
this.psnelContainer.ResumeLayout(false);
this.psnelContainer.PerformLayout();
this.tableLayoutPanel1.ResumeLayout(false);
this.tableLayoutPanel1.PerformLayout();
this.ResumeLayout(false);

}

#endregion

private System.Windows.Forms.Panel psnelContainer;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.Button addbutton;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.ComboBox cmbSearchcriteria;
private System.Windows.Forms.Label lblfrmheader;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button3;





XML
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>New Event Property with event-raising method.</Title>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
            <Shortcut>eventPropertyAndRaiseMethod</Shortcut>
            <Description>A new event property, field, and event-raising method.</Description>
            <Keywords>
                <Keyword>Event</Keyword>
            </Keywords>
        </Header>
        <Snippet>
            <Imports>
                <Import>
                    <Namespace>System</Namespace>
                </Import>
                <Import>
                    <Namespace>System.Collections.Generic</Namespace>
                </Import>
            </Imports>
            <Declarations>
                <Literal Editable="false">
                    <ID>AggregateException</ID>
                    <Function>SimpleTypeName(global::System.AggregateException)</Function>
                </Literal>
                <Literal Editable="false">
                    <ID>ArgumentNullException</ID>
                    <Function>SimpleTypeName(global::System.ArgumentNullException)</Function>
                </Literal>
                <Literal Editable="false">
                    <ID>Delegate</ID>
                    <Function>SimpleTypeName(global::System.Delegate)</Function>
                </Literal>
                <Literal>
                    <ID>EventName</ID>
                    <ToolTip>Name of the event, which should be a past-tense (-"ed") verb for standard events, and a present-tense (-"ing") verb for events which can be canceled by an subscribed event listener.</ToolTip>
                    <Default>Completed</Default>
                </Literal>
                <Literal Editable="true">
                    <ID>EventHandler</ID>
                    <Function>SimpleTypeName(global::System.EventHandler)</Function>
                </Literal>
                <Literal>
                    <ID>EventDescription</ID>
                    <ToolTip>A decription of the action which causes the event to be raised.</ToolTip>
                    <Type>System.String</Type>
                </Literal>
                <Literal Editable="true">
                    <ID>EventArgs</ID>
                    <Function>SimpleTypeName(global::System.EventArgs)</Function>
                    <Type>System.EventArgs</Type>
                </Literal>
                <Literal Editable="false">
                    <ID>Exception</ID>
                    <Function>SimpleTypeName(global::System.Exception)</Function>
                </Literal>
                <Literal Editable="false">
                    <ID>SuppressMessage</ID>
                    <Function>SimpleTypeName(global::System.Diagnostics.CodeAnalysis.SuppressMessage)</Function>
                </Literal>
            </Declarations>
            <Code Language="CSharp" Kind="" >
                    <![CDATA[/// <summary>
        /// Raise the <see cref="$EventName$" /> event.
        /// </summary>
        /// <param name="args">The event data for the event.</param>
        /// <exception cref="$ArgumentNullException$">If <paramref name="args" /> is null.</exception>
        [$SuppressMessage$("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Caught exceptions are re-thrown with an AggregateException")]
        private void On$EventName$($EventArgs$ args)
        {
            if (args == null)
            {
                throw new $ArgumentNullException$("args");
            }
            $EventHandler$ handler = _$EventName$;
            if (_$EventName$ != null)
            {
                $Delegate$[] subscriberArray = handler.GetInvocationList();
                List<$Exception$> errorList = new List<$Exception$>();
                foreach ($EventHandler$ subscriber in subscriberArray)
                {
                    try
                    {
                        subscriber.Invoke(this, args);
                    }
                    catch ($Exception$ error)
                    {
                        errorList.Add(error);
                    }
                }
                if (errorList.Count > 0)
                {
                    throw new $AggregateException$(errorList);
                }
            }
        }

        /// <summary>
        /// $EventDescription$
        /// </summary>
        public event $EventHandler$ $EventName$
        {
            add
            {
                if (_$EventName$ == null)
                    _$EventName$ = value;
                else
                    _$EventName$ += value;
            }
            remove
            {
                if (_$EventName$ != null)
                    _$EventName$ -= value;
            }
        }

        private event $EventHandler$ _$EventName$;]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>
 
Share this answer
 
v2
Comments
CHill60 4-Apr-14 7:30am    
Is this meant to be an answer to your own question? There is far too much code here

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900