Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I had created one user control and one class file, The user control contain save button. When user click save button then i want call the Insert() using ItemClickedEventHandler from infocore class file please help me.

C#: User Control
C#
public partial class toolbar : UserControl
{
    public delegate void ItemClickedEventHandler(System.Object sender, ItemClickEventArgs e);
    public toolbar()
    {
        InitializeComponent();
        inf = new IAToolBar.infocore();
    }
    public event ItemClickedEventHandler ItemClicked;


    public class ItemClickEventArgs
    {
        public string flag;
        public ItemClickEventArgs(string flg)
        {
            flag = flg;
        }
    }

    private void btnsave_Click(object sender, EventArgs e)
    {
        if (ItemClicked != null)
        {
            ItemClicked(sender, new ItemClickEventArgs("Save"));
        }
    }
}

C#: infocore.cs
C#
public void Insert(System.Windows.Forms.Form f)
{
connection.Open();
try
{
query = "INSERT INTO " + f.Tag.ToString().Trim() + " (" + queryfields + ") VALUES (" + formvalues + ") ";
MySqlCommand cmd = new MySqlCommand(query, connection);
cmd.ExecuteNonQuery();
MessageBox.Show("Save Sucessfully", "Inventory Accountancy", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "Inventory Accountancy", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
connection.Close();
}
}
Posted
Updated 26-Mar-13 0:25am
v2

1 solution

See this tutorial[^] for details of how to subscribe to the event handler.
 
Share this answer
 

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