I am developing a windows forms application. I use DataGridView and data binding with LINQ to SQL. It's working. It binds the whole data.
I need some fields instead of whole table data, for example:
The Customers table contains five fields (name, address, mobile, email, age).
I use the code below to get whole data.
private void AssignLocation_Load(object sender, EventArgs e)
{
// Get Datacontext object to connect with data source
SmartxBillingSystemDataContext dc = new SmartxBillingSystemDataContext();
// create table object
Customer customer = new Customer();
var allcustomers = from c in dc.GetTable<Customer>() select c;
// bind to datagrid
customerBindingSource.DataSource = allcustomers;
// now assign binding source to data grid view
dataGridView1.DataSource = customerBindingSource;
}
Now I just need some fields, e.g. Name and Address.
Additionally, I need to add a button in each row like so:
| A Name | An Address | Button |
| Another Name | Fake Address | Button |
How can I achieve this? Please help.
For click event I use below code
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
popUpLocationWindow();
}
private void popUpLocationWindow()
{
MessageBox.Show("I am clicked");
}
But this code not works.