using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace GenericList
{
public partial class frmContact : Form
{
List
public frmContact()
{
InitializeComponent();
}
# region Insert Operation
private void btnInsert_Click(object sender, EventArgs e)
{
Customer cnt = new Customer();
cnt.Name = txtName.Text.Trim();
cnt.Mobile = txtMobile.Text.Trim();
contacts.Add(cnt);
CurrencyManager cm = (CurrencyManager)this.BindingContext[contacts];
cm.Refresh();
dgcontacts.DataSource = contacts;
}
# endregion
#region Update Operation
private void btnUpdate_Click(object sender, EventArgs e)
{
List
if (select.Count > 0) // record found
{
foreach (Customer cnt in select)
{
cnt.Name = txtName.Text.Trim();
cnt.Mobile = txtMobile.Text.Trim();
}
CurrencyManager cm = (CurrencyManager)this.BindingContext[contacts];
cm.Refresh();
dgcontacts.DataSource = contacts;
}
else
{
MessageBox.Show("No records found");
}
}
# endregion
//This function will check for the person name
bool HasName(Customer c)
{
return (c.Name == txtName.Text);
}
# region Delete Operation
private void btnDelete_Click(object sender, EventArgs e)
{
List
if (select.Count > 0) // record found
{
foreach (Customer cnt in select)
{
contacts.Remove(cnt);
}
CurrencyManager cm = (CurrencyManager)this.BindingContext[contacts];
cm.Refresh();
dgcontacts.DataSource = contacts;
}
else
{
MessageBox.Show("No records found");
}
}
# endregion
private void frmContact_Load(object sender, EventArgs e)
{
contacts = new List
}
}
//Customer Class
public class Customer
{
private string _Name;
private string _Mobile;
public string Name
{
get { return _Name; }
set { _Name = value; }
}
public string Mobile
{
get { return _Mobile; }
set { _Mobile = value; }
}
}
}
Thanks for sharing the post with us..
ReplyDeleteweb designer india
free website templates
ReplyDeleteGreat post! I've got an idea here. Thanks for sharing this information. It will really help.
sql insert , Update , delete using c#
ReplyDeletewith code , easy explanation and demo app
http://geeksprogrammings.blogspot.com/2014/05/sql-insert-update-delete-using-c.html